Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 1 | #include "nvme_manager.hpp" |
| 2 | |
Patrick Williams | 7da9858 | 2023-05-10 07:50:46 -0500 | [diff] [blame] | 3 | #include "i2c.h" |
| 4 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 5 | #include "smbus.hpp" |
| 6 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 7 | #include <nlohmann/json.hpp> |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 8 | #include <phosphor-logging/elog-errors.hpp> |
| 9 | #include <phosphor-logging/log.hpp> |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 10 | #include <sdbusplus/message.hpp> |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Led/Physical/server.hpp> |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 12 | |
Patrick Williams | 7da9858 | 2023-05-10 07:50:46 -0500 | [diff] [blame] | 13 | #include <filesystem> |
| 14 | #include <map> |
| 15 | #include <sstream> |
| 16 | #include <string> |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 17 | #define MONITOR_INTERVAL_SECONDS 1 |
Potin Lai | 6e149e9 | 2022-11-23 10:04:05 +0800 | [diff] [blame] | 18 | #define MAX_SMBUS_ERROR_RETRY 0 |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 19 | #define NVME_SSD_SLAVE_ADDRESS 0x6a |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 20 | #define NVME_SSD_VPD_SLAVE_ADDRESS 0x53 |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 21 | #define GPIO_BASE_PATH "/sys/class/gpio/gpio" |
| 22 | #define IS_PRESENT "0" |
| 23 | #define POWERGD "1" |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 24 | #define NOWARNING_STRING "ff" |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 25 | |
| 26 | static constexpr auto configFile = "/etc/nvme/nvme_config.json"; |
| 27 | static constexpr auto delay = std::chrono::milliseconds{100}; |
| 28 | using Json = nlohmann::json; |
| 29 | |
| 30 | static constexpr const uint8_t COMMAND_CODE_0 = 0; |
| 31 | static constexpr const uint8_t COMMAND_CODE_8 = 8; |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 32 | static constexpr const uint8_t CODE_0_LENGTH = 8; |
| 33 | static constexpr const uint8_t CODE_8_LENGTH = 23; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 34 | |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 35 | static constexpr int CapacityFaultMask = 1; |
| 36 | static constexpr int temperatureFaultMask = 1 << 1; |
| 37 | static constexpr int DegradesFaultMask = 1 << 2; |
| 38 | static constexpr int MediaFaultMask = 1 << 3; |
| 39 | static constexpr int BackupDeviceFaultMask = 1 << 4; |
Joseph.Fu | 097562e | 2024-04-16 14:40:49 +0800 | [diff] [blame] | 40 | static constexpr int DriveNotReadyMask = 1 << 6; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 41 | static constexpr int NOWARNING = 255; |
| 42 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 43 | static constexpr int SERIALNUMBER_START_INDEX = 3; |
| 44 | static constexpr int SERIALNUMBER_END_INDEX = 23; |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 45 | static constexpr int MODELNUMBER_START_INDEX = 46; |
| 46 | static constexpr int MODELNUMBER_END_INDEX = 85; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 47 | |
| 48 | static constexpr const int TEMPERATURE_SENSOR_FAILURE = 0x81; |
| 49 | |
Brandon Kim | 8353c5f | 2022-07-08 17:09:23 -0700 | [diff] [blame] | 50 | static std::map<std::string, std::string> map_vendor = { |
Munawar Hussain | 0a0ba60 | 2025-06-17 10:11:25 +0000 | [diff] [blame^] | 51 | {"80 86", "Intel"}, |
| 52 | {"1e f", "Kioxia"}, |
| 53 | {"14 4d", "Samsung"}, |
| 54 | {"1b 96", "Sandisk"}}; |
George Hung | 69b9618 | 2020-08-20 17:19:56 +0800 | [diff] [blame] | 55 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 56 | namespace fs = std::filesystem; |
| 57 | |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 58 | namespace phosphor |
| 59 | { |
| 60 | namespace nvme |
| 61 | { |
| 62 | |
| 63 | using namespace std; |
| 64 | using namespace phosphor::logging; |
| 65 | |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 66 | void Nvme::setNvmeInventoryProperties( |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 67 | NVMeConfig& config, bool present, |
| 68 | const phosphor::nvme::Nvme::NVMeData& nvmeData, |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 69 | const std::string& inventoryPath) |
| 70 | { |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 71 | static std::unordered_map<int, std::string> preSerial; |
| 72 | static std::unordered_map<int, std::string> preSmartWarning; |
| 73 | static std::unordered_map<int, std::string> preStatusFlags; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 74 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 75 | if (preSerial[config.busID].compare(nvmeData.serialNumber) != 0) |
| 76 | { |
| 77 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 78 | ITEM_IFACE, "Present", present); |
| 79 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 80 | ASSET_IFACE, "Manufacturer", |
| 81 | nvmeData.vendor); |
| 82 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 83 | ASSET_IFACE, "SerialNumber", |
| 84 | nvmeData.serialNumber); |
| 85 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 86 | ASSET_IFACE, "Model", |
| 87 | nvmeData.modelNumber); |
| 88 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 89 | NVME_STATUS_IFACE, "DriveLifeUsed", |
| 90 | nvmeData.driveLifeUsed); |
| 91 | preSerial[config.busID] = nvmeData.serialNumber; |
| 92 | } |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 93 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 94 | if (preStatusFlags[config.busID].compare(nvmeData.statusFlags) != 0) |
| 95 | { |
| 96 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 97 | NVME_STATUS_IFACE, "StatusFlags", |
| 98 | nvmeData.statusFlags); |
| 99 | preStatusFlags[config.busID] = nvmeData.statusFlags; |
| 100 | } |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 101 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 102 | if (preSmartWarning[config.busID].compare(nvmeData.smartWarnings) != 0) |
| 103 | { |
| 104 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 105 | NVME_STATUS_IFACE, "SmartWarnings", |
| 106 | nvmeData.smartWarnings); |
| 107 | auto smartWarning = (!nvmeData.smartWarnings.empty()) |
Jayanth Othayoth | e56444a | 2024-12-19 08:35:11 -0600 | [diff] [blame] | 108 | ? std::stoi(nvmeData.smartWarnings, nullptr, 16) |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 109 | : NOWARNING; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 110 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 111 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 112 | NVME_STATUS_IFACE, "CapacityFault", |
| 113 | !(smartWarning & CapacityFaultMask)); |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 114 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 115 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 116 | NVME_STATUS_IFACE, "TemperatureFault", |
| 117 | !(smartWarning & temperatureFaultMask)); |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 118 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 119 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 120 | NVME_STATUS_IFACE, "DegradesFault", |
| 121 | !(smartWarning & DegradesFaultMask)); |
| 122 | |
| 123 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 124 | NVME_STATUS_IFACE, "MediaFault", |
| 125 | !(smartWarning & MediaFaultMask)); |
| 126 | |
| 127 | util::SDBusPlus::setProperty(bus, INVENTORY_BUSNAME, inventoryPath, |
| 128 | NVME_STATUS_IFACE, "BackupDeviceFault", |
| 129 | !(smartWarning & BackupDeviceFaultMask)); |
| 130 | preSmartWarning[config.busID] = nvmeData.smartWarnings; |
| 131 | } |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void Nvme::setFaultLED(const std::string& locateLedGroupPath, |
| 135 | const std::string& faultLedGroupPath, bool request) |
| 136 | { |
| 137 | if (locateLedGroupPath.empty() || faultLedGroupPath.empty()) |
| 138 | { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | // Before toggle LED, check whether is Identify or not. |
| 143 | if (!getLEDGroupState(locateLedGroupPath)) |
| 144 | { |
Brandon Kim | fdffe5c | 2021-03-30 15:07:59 -0700 | [diff] [blame] | 145 | if (getLEDGroupState(faultLedGroupPath) != request) |
| 146 | { |
| 147 | util::SDBusPlus::setProperty(bus, LED_GROUP_BUSNAME, |
| 148 | faultLedGroupPath, LED_GROUP_IFACE, |
| 149 | "Asserted", request); |
| 150 | } |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | void Nvme::setLocateLED(const std::string& locateLedGroupPath, |
| 155 | const std::string& locateLedBusName, |
| 156 | const std::string& locateLedPath, bool isPresent) |
| 157 | { |
| 158 | if (locateLedGroupPath.empty() || locateLedBusName.empty() || |
| 159 | locateLedPath.empty()) |
| 160 | { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | namespace server = sdbusplus::xyz::openbmc_project::Led::server; |
| 165 | |
| 166 | if (!getLEDGroupState(locateLedGroupPath)) |
| 167 | { |
| 168 | if (isPresent) |
| 169 | util::SDBusPlus::setProperty( |
| 170 | bus, locateLedBusName, locateLedPath, LED_CONTROLLER_IFACE, |
| 171 | "State", |
| 172 | server::convertForMessage(server::Physical::Action::On)); |
| 173 | else |
| 174 | util::SDBusPlus::setProperty( |
| 175 | bus, locateLedBusName, locateLedPath, LED_CONTROLLER_IFACE, |
| 176 | "State", |
| 177 | server::convertForMessage(server::Physical::Action::Off)); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | bool Nvme::getLEDGroupState(const std::string& ledPath) |
| 182 | { |
| 183 | auto asserted = util::SDBusPlus::getProperty<bool>( |
| 184 | bus, LED_GROUP_BUSNAME, ledPath, LED_GROUP_IFACE, "Asserted"); |
| 185 | |
| 186 | return asserted; |
| 187 | } |
| 188 | |
| 189 | void Nvme::setLEDsStatus(const phosphor::nvme::Nvme::NVMeConfig& config, |
| 190 | bool success, |
| 191 | const phosphor::nvme::Nvme::NVMeData& nvmeData) |
| 192 | { |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 193 | if (success) |
| 194 | { |
| 195 | if (!nvmeData.smartWarnings.empty()) |
| 196 | { |
| 197 | auto request = |
| 198 | (strcmp(nvmeData.smartWarnings.c_str(), NOWARNING_STRING) == 0) |
| 199 | ? false |
| 200 | : true; |
| 201 | |
| 202 | setFaultLED(config.locateLedGroupPath, config.faultLedGroupPath, |
| 203 | request); |
| 204 | setLocateLED(config.locateLedGroupPath, |
| 205 | config.locateLedControllerBusName, |
| 206 | config.locateLedControllerPath, !request); |
| 207 | } |
| 208 | isError[config.index] = false; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | if (isError[config.index] != true) |
| 213 | { |
| 214 | // Drive is present but can not get data, turn on fault LED. |
| 215 | log<level::ERR>("Drive status is good but can not get data.", |
Brandon Kim | 9b771e2 | 2020-10-05 12:02:01 -0700 | [diff] [blame] | 216 | entry("OBJ_PATH=%s", config.index.c_str())); |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 217 | isError[config.index] = true; |
| 218 | } |
| 219 | |
| 220 | setFaultLED(config.locateLedGroupPath, config.faultLedGroupPath, true); |
| 221 | setLocateLED(config.locateLedGroupPath, |
| 222 | config.locateLedControllerBusName, |
| 223 | config.locateLedControllerPath, false); |
| 224 | } |
| 225 | } |
| 226 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 227 | std::string intToHex(int input) |
| 228 | { |
| 229 | std::stringstream tmp; |
| 230 | tmp << std::hex << input; |
| 231 | |
| 232 | return tmp.str(); |
| 233 | } |
| 234 | |
| 235 | /** @brief Get NVMe info over smbus */ |
George Hung | 5e23bcd | 2021-07-01 12:16:11 +0800 | [diff] [blame] | 236 | bool Nvme::getNVMeInfobyBusID(int busID, |
| 237 | phosphor::nvme::Nvme::NVMeData& nvmeData) |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 238 | { |
| 239 | nvmeData.present = true; |
| 240 | nvmeData.vendor = ""; |
| 241 | nvmeData.serialNumber = ""; |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 242 | nvmeData.modelNumber = ""; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 243 | nvmeData.smartWarnings = ""; |
| 244 | nvmeData.statusFlags = ""; |
| 245 | nvmeData.driveLifeUsed = ""; |
Brandon Kim | d5838d1 | 2021-05-19 12:51:55 -0700 | [diff] [blame] | 246 | nvmeData.sensorValue = static_cast<int8_t>(TEMPERATURE_SENSOR_FAILURE); |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 247 | nvmeData.wcTemp = 0; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 248 | |
| 249 | phosphor::smbus::Smbus smbus; |
| 250 | |
| 251 | unsigned char rsp_data_command_0[I2C_DATA_MAX] = {0}; |
| 252 | unsigned char rsp_data_command_8[I2C_DATA_MAX] = {0}; |
| 253 | |
| 254 | uint8_t tx_data = COMMAND_CODE_0; |
| 255 | |
| 256 | auto init = smbus.smbusInit(busID); |
| 257 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 258 | if (init == -1) |
| 259 | { |
| 260 | if (isErrorSmbus[busID] != true) |
| 261 | { |
| 262 | log<level::ERR>("smbusInit fail!"); |
| 263 | isErrorSmbus[busID] = true; |
| 264 | } |
| 265 | |
| 266 | nvmeData.present = false; |
| 267 | |
| 268 | return nvmeData.present; |
| 269 | } |
| 270 | |
Patrick Williams | f89f153 | 2024-08-16 15:20:48 -0400 | [diff] [blame] | 271 | auto res_int = smbus.SendSmbusRWCmdRAW( |
| 272 | busID, NVME_SSD_SLAVE_ADDRESS, &tx_data, sizeof(tx_data), |
| 273 | rsp_data_command_0, CODE_0_LENGTH); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 274 | |
| 275 | if (res_int < 0) |
| 276 | { |
| 277 | if (isErrorSmbus[busID] != true) |
| 278 | { |
| 279 | log<level::ERR>("Send command code 0 fail!"); |
| 280 | isErrorSmbus[busID] = true; |
| 281 | } |
| 282 | |
| 283 | smbus.smbusClose(busID); |
| 284 | nvmeData.present = false; |
| 285 | return nvmeData.present; |
| 286 | } |
| 287 | |
Joseph.Fu | 097562e | 2024-04-16 14:40:49 +0800 | [diff] [blame] | 288 | if (rsp_data_command_0[1] & DriveNotReadyMask) |
| 289 | { |
| 290 | if (isErrorSmbus[busID] != true) |
| 291 | { |
| 292 | log<level::ERR>("Drive not ready!"); |
| 293 | isErrorSmbus[busID] = true; |
| 294 | } |
| 295 | smbus.smbusClose(busID); |
| 296 | return false; |
| 297 | } |
| 298 | |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 299 | nvmeData.statusFlags = intToHex(rsp_data_command_0[1]); |
| 300 | nvmeData.smartWarnings = intToHex(rsp_data_command_0[2]); |
| 301 | nvmeData.driveLifeUsed = intToHex(rsp_data_command_0[4]); |
George Hung | 9345533 | 2021-01-06 20:57:04 +0800 | [diff] [blame] | 302 | nvmeData.sensorValue = static_cast<int8_t>(rsp_data_command_0[3]); |
| 303 | nvmeData.wcTemp = static_cast<int8_t>(rsp_data_command_0[5]); |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 304 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 305 | tx_data = COMMAND_CODE_8; |
| 306 | |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 307 | res_int = smbus.SendSmbusRWCmdRAW(busID, NVME_SSD_SLAVE_ADDRESS, &tx_data, |
| 308 | sizeof(tx_data), rsp_data_command_8, |
| 309 | CODE_8_LENGTH); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 310 | |
| 311 | if (res_int < 0) |
| 312 | { |
| 313 | if (isErrorSmbus[busID] != true) |
| 314 | { |
| 315 | log<level::ERR>("Send command code 8 fail!"); |
| 316 | isErrorSmbus[busID] = true; |
| 317 | } |
| 318 | |
| 319 | smbus.smbusClose(busID); |
| 320 | nvmeData.present = false; |
| 321 | return nvmeData.present; |
| 322 | } |
| 323 | |
Patrick Williams | f89f153 | 2024-08-16 15:20:48 -0400 | [diff] [blame] | 324 | nvmeData.vendor = |
| 325 | intToHex(rsp_data_command_8[1]) + " " + intToHex(rsp_data_command_8[2]); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 326 | |
George Hung | 69b9618 | 2020-08-20 17:19:56 +0800 | [diff] [blame] | 327 | for (auto iter = map_vendor.begin(); iter != map_vendor.end(); iter++) |
| 328 | { |
| 329 | if (iter->first == nvmeData.vendor) |
| 330 | { |
| 331 | nvmeData.vendor = iter->second; |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 336 | for (int offset = SERIALNUMBER_START_INDEX; offset < SERIALNUMBER_END_INDEX; |
| 337 | offset++) |
| 338 | { |
George Hung | 31c3a2f | 2021-07-29 19:15:14 +0800 | [diff] [blame] | 339 | // Only accept digits/letters/punctuation characters. |
| 340 | if (rsp_data_command_8[offset] >= '!' && |
| 341 | rsp_data_command_8[offset] <= '~') |
George Hung | 69b9618 | 2020-08-20 17:19:56 +0800 | [diff] [blame] | 342 | nvmeData.serialNumber += |
| 343 | static_cast<char>(rsp_data_command_8[offset]); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 344 | } |
| 345 | |
Munawar Hussain | 0a0ba60 | 2025-06-17 10:11:25 +0000 | [diff] [blame^] | 346 | if ((nvmeData.vendor == "Samsung") || (nvmeData.vendor == "Kioxia") || |
| 347 | (nvmeData.vendor == "Sandisk")) |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 348 | { |
| 349 | unsigned char rsp_data_vpd[I2C_DATA_MAX] = {0}; |
| 350 | const int rx_len = (MODELNUMBER_END_INDEX - MODELNUMBER_START_INDEX); |
| 351 | tx_data = MODELNUMBER_START_INDEX; |
| 352 | |
| 353 | auto res_int = |
| 354 | smbus.SendSmbusRWCmdRAW(busID, NVME_SSD_VPD_SLAVE_ADDRESS, &tx_data, |
| 355 | sizeof(tx_data), rsp_data_vpd, rx_len); |
| 356 | |
| 357 | if (res_int < 0) |
| 358 | { |
| 359 | if (isErrorSmbus[busID] != true) |
| 360 | { |
| 361 | log<level::ERR>("Send command read VPD fail!"); |
| 362 | isErrorSmbus[busID] = true; |
| 363 | } |
| 364 | |
| 365 | smbus.smbusClose(busID); |
| 366 | nvmeData.present = false; |
| 367 | return nvmeData.present; |
| 368 | } |
| 369 | |
| 370 | for (int i = 0; i < rx_len; i++) |
| 371 | { |
George Hung | 31c3a2f | 2021-07-29 19:15:14 +0800 | [diff] [blame] | 372 | // Only accept digits/letters/punctuation characters. |
| 373 | if ((rsp_data_vpd[i] >= '!' && rsp_data_vpd[i] <= '~')) |
George Hung | 92a15ba | 2020-09-14 17:14:52 +0800 | [diff] [blame] | 374 | nvmeData.modelNumber += static_cast<char>(rsp_data_vpd[i]); |
| 375 | } |
| 376 | |
| 377 | if (nvmeData.modelNumber.substr(0, nvmeData.vendor.size()) == "SAMSUNG") |
| 378 | nvmeData.modelNumber.erase(0, nvmeData.vendor.size()); |
| 379 | } |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 380 | |
| 381 | smbus.smbusClose(busID); |
| 382 | |
| 383 | isErrorSmbus[busID] = false; |
| 384 | |
| 385 | return nvmeData.present; |
| 386 | } |
| 387 | |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 388 | void Nvme::run() |
| 389 | { |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 390 | init(); |
| 391 | |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 392 | std::function<void()> callback(std::bind(&Nvme::read, this)); |
| 393 | try |
| 394 | { |
Potin Lai | bcae087 | 2022-10-20 15:29:17 +0800 | [diff] [blame] | 395 | u_int64_t interval = monitorIntervalSec * 1000000; |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 396 | _timer.restart(std::chrono::microseconds(interval)); |
| 397 | } |
| 398 | catch (const std::exception& e) |
| 399 | { |
Brandon Kim | 9b771e2 | 2020-10-05 12:02:01 -0700 | [diff] [blame] | 400 | log<level::ERR>("Error in polling loop. "), entry("ERROR=%s", e.what()); |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 404 | /** @brief Parsing NVMe config JSON file */ |
| 405 | Json parseSensorConfig() |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 406 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 407 | std::ifstream jsonFile(configFile); |
| 408 | if (!jsonFile.is_open()) |
| 409 | { |
| 410 | log<level::ERR>("NVMe config JSON file not found"); |
| 411 | } |
| 412 | |
| 413 | auto data = Json::parse(jsonFile, nullptr, false); |
| 414 | if (data.is_discarded()) |
| 415 | { |
| 416 | log<level::ERR>("NVMe config readings JSON parser failure"); |
| 417 | } |
| 418 | |
| 419 | return data; |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 420 | } |
| 421 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 422 | /** @brief Obtain the initial configuration value of NVMe */ |
| 423 | std::vector<phosphor::nvme::Nvme::NVMeConfig> Nvme::getNvmeConfig() |
| 424 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 425 | phosphor::nvme::Nvme::NVMeConfig nvmeConfig; |
| 426 | std::vector<phosphor::nvme::Nvme::NVMeConfig> nvmeConfigs; |
| 427 | int8_t criticalHigh = 0; |
| 428 | int8_t criticalLow = 0; |
| 429 | int8_t maxValue = 0; |
| 430 | int8_t minValue = 0; |
| 431 | int8_t warningHigh = 0; |
| 432 | int8_t warningLow = 0; |
| 433 | |
| 434 | try |
| 435 | { |
| 436 | auto data = parseSensorConfig(); |
| 437 | static const std::vector<Json> empty{}; |
| 438 | std::vector<Json> readings = data.value("config", empty); |
| 439 | std::vector<Json> thresholds = data.value("threshold", empty); |
Patrick Williams | f89f153 | 2024-08-16 15:20:48 -0400 | [diff] [blame] | 440 | monitorIntervalSec = |
| 441 | data.value("monitorIntervalSec", MONITOR_INTERVAL_SECONDS); |
| 442 | maxSmbusErrorRetry = |
| 443 | data.value("maxSmbusErrorRetry", MAX_SMBUS_ERROR_RETRY); |
Potin Lai | bcae087 | 2022-10-20 15:29:17 +0800 | [diff] [blame] | 444 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 445 | if (!thresholds.empty()) |
| 446 | { |
| 447 | for (const auto& instance : thresholds) |
| 448 | { |
| 449 | criticalHigh = instance.value("criticalHigh", 0); |
| 450 | criticalLow = instance.value("criticalLow", 0); |
| 451 | maxValue = instance.value("maxValue", 0); |
| 452 | minValue = instance.value("minValue", 0); |
| 453 | warningHigh = instance.value("warningHigh", 0); |
| 454 | warningLow = instance.value("warningLow", 0); |
| 455 | } |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | log<level::ERR>( |
Manojkiran Eda | 3b2e5a9 | 2024-06-17 14:47:39 +0530 | [diff] [blame] | 460 | "Invalid NVMe config file, thresholds doesn't exist"); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | if (!readings.empty()) |
| 464 | { |
| 465 | for (const auto& instance : readings) |
| 466 | { |
| 467 | uint8_t index = instance.value("NVMeDriveIndex", 0); |
| 468 | uint8_t busID = instance.value("NVMeDriveBusID", 0); |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 469 | std::string faultLedGroupPath = |
| 470 | instance.value("NVMeDriveFaultLEDGroupPath", ""); |
| 471 | std::string locateLedGroupPath = |
| 472 | instance.value("NVMeDriveLocateLEDGroupPath", ""); |
George Hung | 873b5b3 | 2020-06-20 14:56:15 +0800 | [diff] [blame] | 473 | uint16_t presentPin = instance.value("NVMeDrivePresentPin", 0); |
| 474 | uint16_t pwrGoodPin = instance.value("NVMeDrivePwrGoodPin", 0); |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 475 | std::string locateLedControllerBusName = |
| 476 | instance.value("NVMeDriveLocateLEDControllerBusName", ""); |
| 477 | std::string locateLedControllerPath = |
| 478 | instance.value("NVMeDriveLocateLEDControllerPath", ""); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 479 | |
| 480 | nvmeConfig.index = std::to_string(index); |
| 481 | nvmeConfig.busID = busID; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 482 | nvmeConfig.faultLedGroupPath = faultLedGroupPath; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 483 | nvmeConfig.presentPin = presentPin; |
| 484 | nvmeConfig.pwrGoodPin = pwrGoodPin; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 485 | nvmeConfig.locateLedControllerBusName = |
| 486 | locateLedControllerBusName; |
| 487 | nvmeConfig.locateLedControllerPath = locateLedControllerPath; |
| 488 | nvmeConfig.locateLedGroupPath = locateLedGroupPath; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 489 | nvmeConfig.criticalHigh = criticalHigh; |
| 490 | nvmeConfig.criticalLow = criticalLow; |
| 491 | nvmeConfig.warningHigh = warningHigh; |
| 492 | nvmeConfig.warningLow = warningLow; |
| 493 | nvmeConfig.maxValue = maxValue; |
| 494 | nvmeConfig.minValue = minValue; |
| 495 | nvmeConfigs.push_back(nvmeConfig); |
| 496 | } |
| 497 | } |
| 498 | else |
| 499 | { |
Manojkiran Eda | 3b2e5a9 | 2024-06-17 14:47:39 +0530 | [diff] [blame] | 500 | log<level::ERR>("Invalid NVMe config file, config doesn't exist"); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | catch (const Json::exception& e) |
| 504 | { |
Brandon Kim | 9b771e2 | 2020-10-05 12:02:01 -0700 | [diff] [blame] | 505 | log<level::ERR>("Json Exception caught."), entry("MSG=%s", e.what()); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | return nvmeConfigs; |
| 509 | } |
| 510 | |
| 511 | std::string Nvme::getGPIOValueOfNvme(const std::string& fullPath) |
| 512 | { |
| 513 | std::string val; |
| 514 | std::ifstream ifs; |
| 515 | auto retries = 3; |
| 516 | |
| 517 | while (retries != 0) |
| 518 | { |
| 519 | try |
| 520 | { |
| 521 | if (!ifs.is_open()) |
| 522 | ifs.open(fullPath); |
| 523 | ifs.clear(); |
| 524 | ifs.seekg(0); |
| 525 | ifs >> val; |
| 526 | } |
| 527 | catch (const std::exception& e) |
| 528 | { |
| 529 | --retries; |
| 530 | std::this_thread::sleep_for(delay); |
| 531 | log<level::ERR>("Can not open gpio path.", |
Brandon Kim | 9b771e2 | 2020-10-05 12:02:01 -0700 | [diff] [blame] | 532 | entry("MSG=%s", e.what())); |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 533 | continue; |
| 534 | } |
| 535 | break; |
| 536 | } |
| 537 | |
| 538 | ifs.close(); |
| 539 | return val; |
| 540 | } |
| 541 | |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 542 | void Nvme::createNVMeInventory() |
| 543 | { |
Patrick Williams | 05eedaa | 2020-05-13 17:58:42 -0500 | [diff] [blame] | 544 | using Properties = std::map<std::string, std::variant<std::string, bool>>; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 545 | using Interfaces = std::map<std::string, Properties>; |
| 546 | |
| 547 | std::string inventoryPath; |
| 548 | std::map<sdbusplus::message::object_path, Interfaces> obj; |
| 549 | |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 550 | for (const auto& config : configs) |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 551 | { |
| 552 | inventoryPath = "/system/chassis/motherboard/nvme" + config.index; |
| 553 | |
| 554 | obj = {{ |
| 555 | inventoryPath, |
| 556 | {{ITEM_IFACE, {}}, {NVME_STATUS_IFACE, {}}, {ASSET_IFACE, {}}}, |
| 557 | }}; |
| 558 | util::SDBusPlus::CallMethod(bus, INVENTORY_BUSNAME, INVENTORY_NAMESPACE, |
| 559 | INVENTORY_MANAGER_IFACE, "Notify", obj); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | void Nvme::init() |
| 564 | { |
| 565 | createNVMeInventory(); |
| 566 | } |
| 567 | |
Potin Lai | 0314473 | 2023-02-14 22:20:38 +0800 | [diff] [blame] | 568 | void Nvme::readNvmeData(NVMeConfig& config, bool isPwrGood) |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 569 | { |
| 570 | std::string inventoryPath = NVME_INVENTORY_PATH + config.index; |
| 571 | NVMeData nvmeData; |
| 572 | |
| 573 | // get NVMe information through i2c by busID. |
Potin Lai | 0314473 | 2023-02-14 22:20:38 +0800 | [diff] [blame] | 574 | bool success; |
| 575 | |
| 576 | // skip reading nvme data when power good is false |
| 577 | if (isPwrGood) |
| 578 | { |
| 579 | success = getNVMeInfobyBusID(config.busID, nvmeData); |
| 580 | } |
| 581 | else |
| 582 | { |
| 583 | nvmeData.present = false; |
| 584 | nvmeData.sensorValue = static_cast<int8_t>(TEMPERATURE_SENSOR_FAILURE); |
| 585 | success = false; |
| 586 | // Skip retry below when isPwrGood is false because smbus is going to |
| 587 | // fail |
| 588 | nvmeSmbusErrCnt[config.busID] = maxSmbusErrorRetry; |
| 589 | } |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 590 | |
Potin Lai | 6e149e9 | 2022-11-23 10:04:05 +0800 | [diff] [blame] | 591 | if (success) |
| 592 | { |
| 593 | nvmeSmbusErrCnt[config.busID] = 0; |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | if (nvmeSmbusErrCnt[config.busID] < maxSmbusErrorRetry) |
| 598 | { |
Potin Lai | 0314473 | 2023-02-14 22:20:38 +0800 | [diff] [blame] | 599 | // Return early so that we retry |
Potin Lai | 6e149e9 | 2022-11-23 10:04:05 +0800 | [diff] [blame] | 600 | nvmeSmbusErrCnt[config.busID]++; |
| 601 | log<level::INFO>("getNVMeInfobyBusID failed, retry...", |
| 602 | entry("INDEX=%s", config.index.c_str()), |
| 603 | entry("ERRCNT=%u", nvmeSmbusErrCnt[config.busID])); |
| 604 | return; |
| 605 | } |
| 606 | } |
| 607 | |
Potin Lai | 0314473 | 2023-02-14 22:20:38 +0800 | [diff] [blame] | 608 | // find NvmeSSD object by index |
| 609 | auto iter = nvmes.find(config.index); |
| 610 | |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 611 | // can not find. create dbus |
| 612 | if (iter == nvmes.end()) |
| 613 | { |
Brandon Kim | 9b771e2 | 2020-10-05 12:02:01 -0700 | [diff] [blame] | 614 | log<level::INFO>("SSD plug.", entry("INDEX=%s", config.index.c_str())); |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 615 | |
| 616 | std::string objPath = NVME_OBJ_PATH + config.index; |
| 617 | auto nvmeSSD = |
| 618 | std::make_shared<phosphor::nvme::NvmeSSD>(bus, objPath.c_str()); |
| 619 | nvmes.emplace(config.index, nvmeSSD); |
| 620 | |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 621 | setNvmeInventoryProperties(config, true, nvmeData, inventoryPath); |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 622 | nvmeSSD->setSensorValueToDbus(nvmeData.sensorValue); |
George Hung | 9345533 | 2021-01-06 20:57:04 +0800 | [diff] [blame] | 623 | if (nvmeData.wcTemp != 0) |
| 624 | { |
| 625 | config.criticalHigh = nvmeData.wcTemp; |
| 626 | config.warningHigh = nvmeData.wcTemp; |
| 627 | } |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 628 | nvmeSSD->setSensorMaxMin(config.maxValue, config.minValue); |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 629 | nvmeSSD->setSensorThreshold(config.criticalHigh, config.criticalLow, |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 630 | config.warningHigh, config.warningLow); |
| 631 | |
Joseph.Fu | a778272 | 2024-04-19 12:18:07 +0800 | [diff] [blame] | 632 | if (success) |
| 633 | nvmeSSD->checkSensorThreshold(); |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 634 | setLEDsStatus(config, success, nvmeData); |
| 635 | } |
| 636 | else |
| 637 | { |
Chanh Nguyen | e528b0a | 2021-07-14 16:57:57 +0700 | [diff] [blame] | 638 | setNvmeInventoryProperties(config, true, nvmeData, inventoryPath); |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 639 | iter->second->setSensorValueToDbus(nvmeData.sensorValue); |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 640 | if (nvmeData.wcTemp != 0) |
| 641 | { |
George Hung | be34399 | 2021-07-02 09:15:54 +0800 | [diff] [blame] | 642 | config.criticalHigh = nvmeData.wcTemp; |
| 643 | config.warningHigh = nvmeData.wcTemp; |
| 644 | |
George Hung | 831f204 | 2021-05-19 17:02:29 +0800 | [diff] [blame] | 645 | iter->second->setSensorThreshold( |
| 646 | config.criticalHigh, config.criticalLow, config.warningHigh, |
| 647 | config.warningLow); |
| 648 | } |
Joseph.Fu | a778272 | 2024-04-19 12:18:07 +0800 | [diff] [blame] | 649 | if (success) |
| 650 | iter->second->checkSensorThreshold(); |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 651 | setLEDsStatus(config, success, nvmeData); |
| 652 | } |
| 653 | } |
| 654 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 655 | /** @brief Monitor NVMe drives every one second */ |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 656 | void Nvme::read() |
| 657 | { |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 658 | std::string devPresentPath; |
| 659 | std::string devPwrGoodPath; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 660 | std::string inventoryPath; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 661 | |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 662 | for (auto config : configs) |
| 663 | { |
| 664 | NVMeData nvmeData; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 665 | |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 666 | inventoryPath = NVME_INVENTORY_PATH + config.index; |
Patrick Williams | f89f153 | 2024-08-16 15:20:48 -0400 | [diff] [blame] | 667 | devPresentPath = |
| 668 | GPIO_BASE_PATH + std::to_string(config.presentPin) + "/value"; |
| 669 | devPwrGoodPath = |
| 670 | GPIO_BASE_PATH + std::to_string(config.pwrGoodPin) + "/value"; |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 671 | |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 672 | auto presentPinValStr = (config.presentPin) |
| 673 | ? getGPIOValueOfNvme(devPresentPath) |
| 674 | : IS_PRESENT; |
| 675 | auto pwrGoodPinValStr = |
| 676 | (config.pwrGoodPin) ? getGPIOValueOfNvme(devPwrGoodPath) : POWERGD; |
Potin Lai | 76f455e | 2022-09-22 00:11:26 +0800 | [diff] [blame] | 677 | const bool isPwrGood = (pwrGoodPinValStr == POWERGD); |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 678 | |
| 679 | if (presentPinValStr != IS_PRESENT) |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 680 | { |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 681 | // Drive not present, remove nvme d-bus path , |
| 682 | // clean all properties in inventory |
| 683 | // and turn off fault and locate LED |
Vijay Khemka | e41b2e4 | 2020-04-21 09:23:10 -0700 | [diff] [blame] | 684 | |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 685 | setFaultLED(config.locateLedGroupPath, config.faultLedGroupPath, |
| 686 | false); |
| 687 | setLocateLED(config.locateLedGroupPath, |
| 688 | config.locateLedControllerBusName, |
| 689 | config.locateLedControllerPath, false); |
| 690 | |
| 691 | nvmeData = NVMeData(); |
| 692 | setNvmeInventoryProperties(config, false, nvmeData, inventoryPath); |
| 693 | nvmes.erase(config.index); |
| 694 | continue; |
| 695 | } |
| 696 | |
Potin Lai | 76f455e | 2022-09-22 00:11:26 +0800 | [diff] [blame] | 697 | if (!isPwrGood) |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 698 | { |
| 699 | // IFDET should be used to provide the final say |
| 700 | // in SSD's presence - IFDET showing SSD is present |
| 701 | // but the power is off (if the drive is plugged in) |
| 702 | // is a valid state. |
| 703 | |
| 704 | setFaultLED(config.locateLedGroupPath, config.faultLedGroupPath, |
| 705 | true); |
| 706 | setLocateLED(config.locateLedGroupPath, |
| 707 | config.locateLedControllerBusName, |
| 708 | config.locateLedControllerPath, false); |
| 709 | |
| 710 | nvmeData = NVMeData(); |
| 711 | setNvmeInventoryProperties(config, true, nvmeData, inventoryPath); |
| 712 | |
| 713 | if (isErrorPower[config.index] != true) |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 714 | { |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 715 | log<level::ERR>( |
| 716 | "Present pin is true but power good pin is false.", |
| 717 | entry("INDEX=%s", config.index.c_str())); |
| 718 | log<level::ERR>("Erase SSD from map and d-bus.", |
| 719 | entry("INDEX=%s", config.index.c_str())); |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 720 | |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 721 | isErrorPower[config.index] = true; |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 722 | } |
| 723 | } |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 724 | else |
| 725 | { |
| 726 | isErrorPower[config.index] = false; |
| 727 | } |
Tony Lee | 8965921 | 2019-06-21 17:34:14 +0800 | [diff] [blame] | 728 | |
Potin Lai | aef8fa0 | 2022-09-21 19:10:30 +0800 | [diff] [blame] | 729 | // Keep reading to report the invalid temperature |
| 730 | // (To make thermal loop know that the sensor reading |
| 731 | // is invalid). |
Potin Lai | 0314473 | 2023-02-14 22:20:38 +0800 | [diff] [blame] | 732 | readNvmeData(config, isPwrGood); |
Potin Lai | 6e149e9 | 2022-11-23 10:04:05 +0800 | [diff] [blame] | 733 | if (nvmes.find(config.index) != nvmes.end()) |
| 734 | { |
| 735 | nvmes.find(config.index)->second->setSensorAvailability(isPwrGood); |
| 736 | } |
Tony Lee | 6c59501 | 2019-06-19 10:54:59 +0800 | [diff] [blame] | 737 | } |
Tony Lee | 84d430c | 2019-06-13 15:26:15 +0800 | [diff] [blame] | 738 | } |
| 739 | } // namespace nvme |
| 740 | } // namespace phosphor |