Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 1 | #include "storagehandler.hpp" |
| 2 | |
| 3 | #include "fruread.hpp" |
| 4 | #include "read_fru_data.hpp" |
| 5 | #include "selutility.hpp" |
| 6 | #include "sensorhandler.hpp" |
| 7 | #include "storageaddsel.hpp" |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 8 | |
Lei YU | 52d9124 | 2017-10-17 22:52:28 +0800 | [diff] [blame] | 9 | #include <arpa/inet.h> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 10 | #include <mapper.h> |
| 11 | #include <systemd/sd-bus.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
Lei YU | 52d9124 | 2017-10-17 22:52:28 +0800 | [diff] [blame] | 14 | #include <chrono> |
| 15 | #include <cstdio> |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 16 | #include <cstring> |
Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 17 | #include <filesystem> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 18 | #include <ipmid/api.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 19 | #include <ipmid/utils.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 20 | #include <phosphor-logging/elog-errors.hpp> |
| 21 | #include <phosphor-logging/log.hpp> |
| 22 | #include <sdbusplus/server.hpp> |
| 23 | #include <string> |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 24 | #include <variant> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 25 | #include <xyz/openbmc_project/Common/error.hpp> |
| 26 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 27 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 28 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 29 | unsigned int g_sel_time = 0xFFFFFFFF; |
Patrick Venture | db0cbe6 | 2019-09-09 14:47:22 -0700 | [diff] [blame] | 30 | namespace ipmi |
| 31 | { |
| 32 | namespace sensor |
| 33 | { |
| 34 | extern const IdInfoMap sensors; |
| 35 | } // namespace sensor |
| 36 | } // namespace ipmi |
| 37 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 38 | extern const FruMap frus; |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 39 | constexpr uint8_t eventDataSize = 3; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 40 | namespace |
| 41 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 42 | constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime"; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 43 | constexpr auto BMC_TIME_PATH = "/xyz/openbmc_project/time/bmc"; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 44 | constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 45 | constexpr auto PROPERTY_ELAPSED = "Elapsed"; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 46 | |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame^] | 47 | constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry"; |
| 48 | constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry"; |
| 49 | constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 50 | } // namespace |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 51 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 52 | namespace cache |
| 53 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 54 | /* |
| 55 | * This cache contains the object paths of the logging entries sorted in the |
| 56 | * order of the filename(numeric order). The cache is initialized by |
| 57 | * invoking readLoggingObjectPaths with the cache as the parameter. The |
| 58 | * cache is invoked in the execution of the Get SEL info and Delete SEL |
| 59 | * entry command. The Get SEL Info command is typically invoked before the |
| 60 | * Get SEL entry command, so the cache is utilized for responding to Get SEL |
| 61 | * entry command. The cache is invalidated by clearing after Delete SEL |
| 62 | * entry and Clear SEL command. |
| 63 | */ |
| 64 | ipmi::sel::ObjectPaths paths; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 65 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 66 | } // namespace cache |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 67 | |
| 68 | using InternalFailure = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 69 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 70 | using namespace phosphor::logging; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 71 | using namespace ipmi::fru; |
| 72 | |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame^] | 73 | using SELRecordID = uint16_t; |
| 74 | using SELEntry = ipmi::sel::SELEventRecordFormat; |
| 75 | using SELCacheMap = std::map<SELRecordID, SELEntry>; |
| 76 | |
| 77 | SELCacheMap selCacheMap __attribute__((init_priority(101))); |
| 78 | |
| 79 | std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p) |
| 80 | { |
| 81 | namespace fs = std::filesystem; |
| 82 | fs::path entryPath(p); |
| 83 | auto id = static_cast<uint16_t>(std::stoul(entryPath.filename().string())); |
| 84 | // TODO: parse the sel data |
| 85 | return {id, {}}; |
| 86 | } |
| 87 | |
| 88 | void initSELCache() |
| 89 | { |
| 90 | try |
| 91 | { |
| 92 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 93 | } |
| 94 | catch (const sdbusplus::exception::exception& e) |
| 95 | { |
| 96 | log<level::ERR>("Failed to get logging object paths"); |
| 97 | return; |
| 98 | } |
| 99 | for (const auto& p : cache::paths) |
| 100 | { |
| 101 | selCacheMap.insert(parseLoggingEntry(p)); |
| 102 | } |
| 103 | } |
| 104 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 105 | /** |
| 106 | * @enum Device access mode |
| 107 | */ |
| 108 | enum class AccessMode |
| 109 | { |
| 110 | bytes, ///< Device is accessed by bytes |
| 111 | words ///< Device is accessed by words |
| 112 | }; |
| 113 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 114 | /** @brief implements the get SEL Info command |
| 115 | * @returns IPMI completion code plus response data |
| 116 | * - selVersion - SEL revision |
| 117 | * - entries - Number of log entries in SEL. |
| 118 | * - freeSpace - Free Space in bytes. |
| 119 | * - addTimeStamp - Most recent addition timestamp |
| 120 | * - eraseTimeStamp - Most recent erase timestamp |
| 121 | * - operationSupport - Reserve & Delete SEL operations supported |
| 122 | */ |
| 123 | |
| 124 | ipmi::RspType<uint8_t, // SEL revision. |
| 125 | uint16_t, // number of log entries in SEL. |
| 126 | uint16_t, // free Space in bytes. |
| 127 | uint32_t, // most recent addition timestamp |
| 128 | uint32_t, // most recent erase timestamp. |
| 129 | |
| 130 | bool, // SEL allocation info supported |
| 131 | bool, // reserve SEL supported |
| 132 | bool, // partial Add SEL Entry supported |
| 133 | bool, // delete SEL supported |
| 134 | uint3_t, // reserved |
| 135 | bool // overflow flag |
| 136 | > |
| 137 | ipmiStorageGetSelInfo() |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 138 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 139 | uint16_t entries = 0; |
| 140 | // Most recent addition timestamp. |
| 141 | uint32_t addTimeStamp = ipmi::sel::invalidTimeStamp; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 142 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 143 | try |
| 144 | { |
| 145 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 146 | } |
Patrick Williams | ef1259b | 2021-09-02 09:12:33 -0500 | [diff] [blame] | 147 | catch (const sdbusplus::exception::exception& e) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 148 | { |
| 149 | // No action if reading log objects have failed for this command. |
| 150 | // readLoggingObjectPaths will throw exception if there are no log |
| 151 | // entries. The command will be responded with number of SEL entries |
| 152 | // as 0. |
| 153 | } |
| 154 | |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 155 | if (!cache::paths.empty()) |
| 156 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 157 | entries = static_cast<uint16_t>(cache::paths.size()); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 158 | |
| 159 | try |
| 160 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 161 | addTimeStamp = static_cast<uint32_t>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 162 | (ipmi::sel::getEntryTimeStamp(cache::paths.back()).count())); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 163 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 164 | catch (const InternalFailure& e) |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 165 | { |
| 166 | } |
| 167 | catch (const std::runtime_error& e) |
| 168 | { |
| 169 | log<level::ERR>(e.what()); |
| 170 | } |
| 171 | } |
| 172 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 173 | constexpr uint8_t selVersion = ipmi::sel::selVersion; |
| 174 | constexpr uint16_t freeSpace = 0xFFFF; |
| 175 | constexpr uint32_t eraseTimeStamp = ipmi::sel::invalidTimeStamp; |
| 176 | constexpr uint3_t reserved{0}; |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 177 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 178 | return ipmi::responseSuccess( |
| 179 | selVersion, entries, freeSpace, addTimeStamp, eraseTimeStamp, |
| 180 | ipmi::sel::operationSupport::getSelAllocationInfo, |
| 181 | ipmi::sel::operationSupport::reserveSel, |
| 182 | ipmi::sel::operationSupport::partialAddSelEntry, |
| 183 | ipmi::sel::operationSupport::deleteSel, reserved, |
| 184 | ipmi::sel::operationSupport::overflow); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 185 | } |
| 186 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 187 | ipmi_ret_t getSELEntry(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 188 | ipmi_request_t request, ipmi_response_t response, |
| 189 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 190 | { |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 191 | if (*data_len != sizeof(ipmi::sel::GetSELEntryRequest)) |
| 192 | { |
| 193 | *data_len = 0; |
| 194 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 195 | } |
| 196 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 197 | auto requestData = |
| 198 | reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 199 | |
| 200 | if (requestData->reservationID != 0) |
| 201 | { |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 202 | if (!checkSELReservation(requestData->reservationID)) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 203 | { |
| 204 | *data_len = 0; |
| 205 | return IPMI_CC_INVALID_RESERVATION_ID; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if (cache::paths.empty()) |
| 210 | { |
| 211 | *data_len = 0; |
| 212 | return IPMI_CC_SENSOR_INVALID; |
| 213 | } |
| 214 | |
| 215 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 216 | |
| 217 | // Check for the requested SEL Entry. |
| 218 | if (requestData->selRecordID == ipmi::sel::firstEntry) |
| 219 | { |
| 220 | iter = cache::paths.begin(); |
| 221 | } |
| 222 | else if (requestData->selRecordID == ipmi::sel::lastEntry) |
| 223 | { |
| 224 | iter = cache::paths.end(); |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
| 229 | std::to_string(requestData->selRecordID); |
| 230 | |
| 231 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 232 | if (iter == cache::paths.end()) |
| 233 | { |
| 234 | *data_len = 0; |
| 235 | return IPMI_CC_SENSOR_INVALID; |
| 236 | } |
| 237 | } |
| 238 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 239 | ipmi::sel::GetSELEntryResponse record{}; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 240 | |
| 241 | // Convert the log entry into SEL record. |
| 242 | try |
| 243 | { |
| 244 | record = ipmi::sel::convertLogEntrytoSEL(*iter); |
| 245 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 246 | catch (const InternalFailure& e) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 247 | { |
| 248 | *data_len = 0; |
| 249 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 250 | } |
| 251 | catch (const std::runtime_error& e) |
| 252 | { |
| 253 | log<level::ERR>(e.what()); |
| 254 | *data_len = 0; |
| 255 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 256 | } |
| 257 | |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 258 | // Identify the next SEL record ID |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 259 | if (iter != cache::paths.end()) |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 260 | { |
| 261 | ++iter; |
| 262 | if (iter == cache::paths.end()) |
| 263 | { |
| 264 | record.nextRecordID = ipmi::sel::lastEntry; |
| 265 | } |
| 266 | else |
| 267 | { |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 268 | namespace fs = std::filesystem; |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 269 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 270 | record.nextRecordID = static_cast<uint16_t>( |
| 271 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | record.nextRecordID = ipmi::sel::lastEntry; |
| 277 | } |
| 278 | |
| 279 | if (requestData->readLength == ipmi::sel::entireRecord) |
| 280 | { |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 281 | std::memcpy(response, &record, sizeof(record)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 282 | *data_len = sizeof(record); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | if (requestData->offset >= ipmi::sel::selRecordSize || |
| 287 | requestData->readLength > ipmi::sel::selRecordSize) |
| 288 | { |
| 289 | *data_len = 0; |
| 290 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 291 | } |
| 292 | |
| 293 | auto diff = ipmi::sel::selRecordSize - requestData->offset; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 294 | auto readLength = |
| 295 | std::min(diff, static_cast<int>(requestData->readLength)); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 296 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 297 | std::memcpy(response, &record.nextRecordID, |
| 298 | sizeof(record.nextRecordID)); |
| 299 | std::memcpy(static_cast<uint8_t*>(response) + |
| 300 | sizeof(record.nextRecordID), |
Lei YU | af378fa | 2020-12-02 16:28:57 +0800 | [diff] [blame] | 301 | &record.event.eventRecord.recordID + requestData->offset, |
| 302 | readLength); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 303 | *data_len = sizeof(record.nextRecordID) + readLength; |
| 304 | } |
| 305 | |
| 306 | return IPMI_CC_OK; |
| 307 | } |
| 308 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 309 | /** @brief implements the delete SEL entry command |
| 310 | * @request |
| 311 | * - reservationID; // reservation ID. |
| 312 | * - selRecordID; // SEL record ID. |
| 313 | * |
| 314 | * @returns ipmi completion code plus response data |
| 315 | * - Record ID of the deleted record |
| 316 | */ |
| 317 | ipmi::RspType<uint16_t // deleted record ID |
| 318 | > |
| 319 | deleteSELEntry(uint16_t reservationID, uint16_t selRecordID) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 320 | { |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 321 | |
Brad Bishop | 1a4117b | 2018-11-21 15:48:18 -0500 | [diff] [blame] | 322 | namespace fs = std::filesystem; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 323 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 324 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 325 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 326 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 327 | } |
| 328 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 329 | // Per the IPMI spec, need to cancel the reservation when a SEL entry is |
| 330 | // deleted |
| 331 | cancelSELReservation(); |
| 332 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 333 | try |
| 334 | { |
| 335 | ipmi::sel::readLoggingObjectPaths(cache::paths); |
| 336 | } |
Patrick Williams | ef1259b | 2021-09-02 09:12:33 -0500 | [diff] [blame] | 337 | catch (const sdbusplus::exception::exception& e) |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 338 | { |
| 339 | // readLoggingObjectPaths will throw exception if there are no error |
| 340 | // log entries. |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 341 | return ipmi::responseSensorInvalid(); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 342 | } |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 343 | |
| 344 | if (cache::paths.empty()) |
| 345 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 346 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | ipmi::sel::ObjectPaths::const_iterator iter; |
| 350 | uint16_t delRecordID = 0; |
| 351 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 352 | if (selRecordID == ipmi::sel::firstEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 353 | { |
| 354 | iter = cache::paths.begin(); |
| 355 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 356 | delRecordID = static_cast<uint16_t>( |
| 357 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 358 | } |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 359 | else if (selRecordID == ipmi::sel::lastEntry) |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 360 | { |
| 361 | iter = cache::paths.end(); |
| 362 | fs::path path(*iter); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 363 | delRecordID = static_cast<uint16_t>( |
| 364 | std::stoul(std::string(path.filename().c_str()))); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 365 | } |
| 366 | else |
| 367 | { |
| 368 | std::string objPath = std::string(ipmi::sel::logBasePath) + "/" + |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 369 | std::to_string(selRecordID); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 370 | |
| 371 | iter = std::find(cache::paths.begin(), cache::paths.end(), objPath); |
| 372 | if (iter == cache::paths.end()) |
| 373 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 374 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 375 | } |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 376 | delRecordID = selRecordID; |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 380 | std::string service; |
| 381 | |
| 382 | try |
| 383 | { |
| 384 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, *iter); |
| 385 | } |
| 386 | catch (const std::runtime_error& e) |
| 387 | { |
| 388 | log<level::ERR>(e.what()); |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 389 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 390 | } |
| 391 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 392 | auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(), |
| 393 | ipmi::sel::logDeleteIntf, "Delete"); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 394 | auto reply = bus.call(methodCall); |
| 395 | if (reply.is_method_error()) |
| 396 | { |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 397 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // Invalidate the cache of dbus entry objects. |
| 401 | cache::paths.clear(); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 402 | |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 403 | return ipmi::responseSuccess(delRecordID); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 404 | } |
| 405 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 406 | /** @brief implements the Clear SEL command |
| 407 | * @request |
| 408 | * - reservationID // Reservation ID. |
| 409 | * - clr // char array { 'C'(0x43h), 'L'(0x4Ch), 'R'(0x52h) } |
| 410 | * - eraseOperation; // requested operation. |
| 411 | * |
| 412 | * @returns ipmi completion code plus response data |
| 413 | * - erase status |
| 414 | */ |
| 415 | |
| 416 | ipmi::RspType<uint8_t // erase status |
| 417 | > |
| 418 | clearSEL(uint16_t reservationID, const std::array<char, 3>& clr, |
| 419 | uint8_t eraseOperation) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 420 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 421 | static constexpr std::array<char, 3> clrOk = {'C', 'L', 'R'}; |
| 422 | if (clr != clrOk) |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 423 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 424 | return ipmi::responseInvalidFieldRequest(); |
Jason M. Bills | 851acb1 | 2019-02-04 14:06:57 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 427 | if (!checkSELReservation(reservationID)) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 428 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 429 | return ipmi::responseInvalidReservationId(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 430 | } |
| 431 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 432 | /* |
| 433 | * Erasure status cannot be fetched from DBUS, so always return erasure |
| 434 | * status as `erase completed`. |
| 435 | */ |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 436 | if (eraseOperation == ipmi::sel::getEraseStatus) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 437 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 438 | return ipmi::responseSuccess( |
| 439 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 440 | } |
| 441 | |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 442 | // Per the IPMI spec, need to cancel any reservation when the SEL is cleared |
| 443 | cancelSELReservation(); |
| 444 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 445 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 446 | ipmi::sel::ObjectPaths objectPaths; |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 447 | auto depth = 0; |
| 448 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 449 | auto mapperCall = |
| 450 | bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath, |
| 451 | ipmi::sel::mapperIntf, "GetSubTreePaths"); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 452 | mapperCall.append(ipmi::sel::logBasePath); |
| 453 | mapperCall.append(depth); |
| 454 | mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf})); |
| 455 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 456 | try |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 457 | { |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 458 | auto reply = bus.call(mapperCall); |
| 459 | if (reply.is_method_error()) |
| 460 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 461 | return ipmi::responseSuccess( |
| 462 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 463 | } |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 464 | |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 465 | reply.read(objectPaths); |
| 466 | if (objectPaths.empty()) |
| 467 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 468 | return ipmi::responseSuccess( |
| 469 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | e59abfb | 2018-08-06 18:46:27 +0530 | [diff] [blame] | 470 | } |
| 471 | } |
Patrick Williams | ef1259b | 2021-09-02 09:12:33 -0500 | [diff] [blame] | 472 | catch (const sdbusplus::exception::exception& e) |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 473 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 474 | return ipmi::responseSuccess( |
| 475 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | std::string service; |
| 479 | |
| 480 | try |
| 481 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 482 | service = ipmi::getService(bus, ipmi::sel::logDeleteIntf, |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 483 | objectPaths.front()); |
| 484 | } |
| 485 | catch (const std::runtime_error& e) |
| 486 | { |
| 487 | log<level::ERR>(e.what()); |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 488 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | for (const auto& iter : objectPaths) |
| 492 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 493 | auto methodCall = bus.new_method_call( |
| 494 | service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete"); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 495 | |
| 496 | auto reply = bus.call(methodCall); |
| 497 | if (reply.is_method_error()) |
| 498 | { |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 499 | return ipmi::responseUnspecifiedError(); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | // Invalidate the cache of dbus entry objects. |
| 504 | cache::paths.clear(); |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 505 | return ipmi::responseSuccess( |
| 506 | static_cast<uint8_t>(ipmi::sel::eraseComplete)); |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 507 | } |
| 508 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 509 | /** @brief implements the get SEL time command |
| 510 | * @returns IPMI completion code plus response data |
| 511 | * -current time |
| 512 | */ |
| 513 | ipmi::RspType<uint32_t> // current time |
| 514 | ipmiStorageGetSelTime() |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 515 | { |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 516 | using namespace std::chrono; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 517 | uint64_t bmc_time_usec = 0; |
| 518 | std::stringstream bmcTime; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 519 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 520 | try |
| 521 | { |
| 522 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 523 | auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH); |
Vernon Mauery | 16b8693 | 2019-05-01 08:36:11 -0700 | [diff] [blame] | 524 | std::variant<uint64_t> value; |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 525 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 526 | // Get bmc time |
| 527 | auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 528 | DBUS_PROPERTIES, "Get"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 529 | |
| 530 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED); |
| 531 | auto reply = bus.call(method); |
| 532 | if (reply.is_method_error()) |
| 533 | { |
| 534 | log<level::ERR>("Error getting time", |
| 535 | entry("SERVICE=%s", service.c_str()), |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 536 | entry("PATH=%s", BMC_TIME_PATH)); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 537 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 538 | } |
| 539 | reply.read(value); |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 540 | bmc_time_usec = std::get<uint64_t>(value); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 541 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 542 | catch (const InternalFailure& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 543 | { |
| 544 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 545 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 546 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 547 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 548 | { |
| 549 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 550 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 551 | } |
| 552 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 553 | bmcTime << "BMC time:" |
| 554 | << duration_cast<seconds>(microseconds(bmc_time_usec)).count(); |
| 555 | log<level::DEBUG>(bmcTime.str().c_str()); |
Nagaraju Goruganti | 8960b7c | 2018-04-29 22:38:40 -0500 | [diff] [blame] | 556 | |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 557 | // Time is really long int but IPMI wants just uint32. This works okay until |
| 558 | // the number of seconds since 1970 overflows uint32 size.. Still a whole |
| 559 | // lot of time here to even think about that. |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 560 | return ipmi::responseSuccess( |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 561 | duration_cast<seconds>(microseconds(bmc_time_usec)).count()); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 562 | } |
| 563 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 564 | /** @brief implements the set SEL time command |
| 565 | * @param selDeviceTime - epoch time |
| 566 | * -local time as the number of seconds from 00:00:00, January 1, 1970 |
| 567 | * @returns IPMI completion code |
| 568 | */ |
| 569 | ipmi::RspType<> ipmiStorageSetSelTime(uint32_t selDeviceTime) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 570 | { |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 571 | using namespace std::chrono; |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 572 | microseconds usec{seconds(selDeviceTime)}; |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 573 | |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 574 | try |
| 575 | { |
| 576 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 577 | auto service = ipmi::getService(bus, TIME_INTERFACE, BMC_TIME_PATH); |
Andrew Geissler | 6467ed2 | 2020-05-16 16:03:53 -0500 | [diff] [blame] | 578 | std::variant<uint64_t> value{(uint64_t)usec.count()}; |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 579 | |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 580 | // Set bmc time |
| 581 | auto method = bus.new_method_call(service.c_str(), BMC_TIME_PATH, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 582 | DBUS_PROPERTIES, "Set"); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 583 | |
| 584 | method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value); |
| 585 | auto reply = bus.call(method); |
| 586 | if (reply.is_method_error()) |
| 587 | { |
| 588 | log<level::ERR>("Error setting time", |
| 589 | entry("SERVICE=%s", service.c_str()), |
George Liu | 4d623e9 | 2020-05-25 16:51:57 +0800 | [diff] [blame] | 590 | entry("PATH=%s", BMC_TIME_PATH)); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 591 | return ipmi::responseUnspecifiedError(); |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 592 | } |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 593 | } |
Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 594 | catch (const InternalFailure& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 595 | { |
| 596 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 597 | return ipmi::responseUnspecifiedError(); |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 598 | } |
Tom Joseph | 30fd0a1 | 2019-09-24 06:53:22 +0530 | [diff] [blame] | 599 | catch (const std::exception& e) |
Lei YU | e893939 | 2017-06-15 10:45:05 +0800 | [diff] [blame] | 600 | { |
| 601 | log<level::ERR>(e.what()); |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 602 | return ipmi::responseUnspecifiedError(); |
Norman James | 8233044 | 2015-11-19 16:53:26 -0600 | [diff] [blame] | 603 | } |
Vishwanatha Subbanna | 5fba7a6 | 2016-09-01 14:06:07 +0530 | [diff] [blame] | 604 | |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 605 | return ipmi::responseSuccess(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 606 | } |
| 607 | |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 608 | /** @brief implements the reserve SEL command |
| 609 | * @returns IPMI completion code plus response data |
| 610 | * - SEL reservation ID. |
| 611 | */ |
| 612 | ipmi::RspType<uint16_t> ipmiStorageReserveSel() |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 613 | { |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 614 | return ipmi::responseSuccess(reserveSel()); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 615 | } |
| 616 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 617 | /** @brief implements the Add SEL entry command |
| 618 | * @request |
| 619 | * |
| 620 | * - recordID ID used for SEL Record access |
| 621 | * - recordType Record Type |
| 622 | * - timeStamp Time when event was logged. LS byte first |
| 623 | * - generatorID software ID if event was generated from |
| 624 | * system software |
| 625 | * - evmRev event message format version |
| 626 | * - sensorType sensor type code for service that generated |
| 627 | * the event |
| 628 | * - sensorNumber number of sensors that generated the event |
| 629 | * - eventDir event dir |
| 630 | * - eventData event data field contents |
| 631 | * |
| 632 | * @returns ipmi completion code plus response data |
| 633 | * - RecordID of the Added SEL entry |
| 634 | */ |
| 635 | ipmi::RspType<uint16_t // recordID of the Added SEL entry |
| 636 | > |
| 637 | ipmiStorageAddSEL(uint16_t recordID, uint8_t recordType, uint32_t timeStamp, |
| 638 | uint16_t generatorID, uint8_t evmRev, uint8_t sensorType, |
| 639 | uint8_t sensorNumber, uint8_t eventDir, |
| 640 | std::array<uint8_t, eventDataSize> eventData) |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 641 | { |
Jason M. Bills | 13e67c8 | 2018-09-10 14:12:16 -0700 | [diff] [blame] | 642 | // Per the IPMI spec, need to cancel the reservation when a SEL entry is |
| 643 | // added |
| 644 | cancelSELReservation(); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 645 | // Hostboot sends SEL with OEM record type 0xDE to indicate that there is |
| 646 | // a maintenance procedure associated with eSEL record. |
| 647 | static constexpr auto procedureType = 0xDE; |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 648 | if (recordType == procedureType) |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 649 | { |
| 650 | // In the OEM record type 0xDE, byte 11 in the SEL record indicate the |
| 651 | // procedure number. |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 652 | createProcedureLogEntry(sensorType); |
Tom Joseph | b647d5b | 2017-10-31 17:25:33 +0530 | [diff] [blame] | 653 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 654 | |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 655 | return ipmi::responseSuccess(recordID); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 656 | } |
| 657 | |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 658 | bool isFruPresent(const std::string& fruPath) |
| 659 | { |
| 660 | using namespace ipmi::fru; |
| 661 | |
| 662 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 663 | |
| 664 | auto propValue = |
| 665 | ipmi::getDbusProperty(bus, invMgrInterface, invObjPath + fruPath, |
| 666 | invItemInterface, itemPresentProp); |
| 667 | |
| 668 | return std::get<bool>(propValue); |
| 669 | } |
| 670 | |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 671 | /** @brief implements the get FRU Inventory Area Info command |
| 672 | * |
| 673 | * @returns IPMI completion code plus response data |
| 674 | * - FRU Inventory area size in bytes, |
| 675 | * - access bit |
| 676 | **/ |
| 677 | ipmi::RspType<uint16_t, // FRU Inventory area size in bytes, |
| 678 | uint8_t // access size (bytes / words) |
| 679 | > |
| 680 | ipmiStorageGetFruInvAreaInfo(uint8_t fruID) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 681 | { |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 682 | |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 683 | auto iter = frus.find(fruID); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 684 | if (iter == frus.end()) |
| 685 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 686 | return ipmi::responseSensorInvalid(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 687 | } |
| 688 | |
Kirill Pakhomov | fa6e209 | 2020-04-24 18:57:15 +0300 | [diff] [blame] | 689 | auto path = iter->second[0].path; |
| 690 | if (!isFruPresent(path)) |
| 691 | { |
| 692 | return ipmi::responseSensorInvalid(); |
| 693 | } |
| 694 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 695 | try |
| 696 | { |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 697 | return ipmi::responseSuccess( |
| 698 | static_cast<uint16_t>(getFruAreaData(fruID).size()), |
| 699 | static_cast<uint8_t>(AccessMode::bytes)); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 700 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 701 | catch (const InternalFailure& e) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 702 | { |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 703 | log<level::ERR>(e.what()); |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 704 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 705 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 706 | } |
| 707 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 708 | /**@brief implements the Read FRU Data command |
| 709 | * @param fruDeviceId - FRU device ID. FFh = reserved |
| 710 | * @param offset - FRU inventory offset to read |
| 711 | * @param readCount - count to read |
| 712 | * |
| 713 | * @return IPMI completion code plus response data |
| 714 | * - returnCount - response data count. |
| 715 | * - data - response data |
| 716 | */ |
| 717 | ipmi::RspType<uint8_t, // count returned |
| 718 | std::vector<uint8_t>> // FRU data |
| 719 | ipmiStorageReadFruData(uint8_t fruDeviceId, uint16_t offset, |
| 720 | uint8_t readCount) |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 721 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 722 | if (fruDeviceId == 0xFF) |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 723 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 724 | return ipmi::responseInvalidFieldRequest(); |
Tom Joseph | 187f564 | 2018-03-29 13:49:06 +0530 | [diff] [blame] | 725 | } |
| 726 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 727 | auto iter = frus.find(fruDeviceId); |
| 728 | if (iter == frus.end()) |
| 729 | { |
| 730 | return ipmi::responseSensorInvalid(); |
| 731 | } |
| 732 | |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 733 | try |
| 734 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 735 | const auto& fruArea = getFruAreaData(fruDeviceId); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 736 | auto size = fruArea.size(); |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 737 | |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 738 | if (offset >= size) |
| 739 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 740 | return ipmi::responseParmOutOfRange(); |
Tom Joseph | efcd68b | 2018-04-26 18:46:27 +0530 | [diff] [blame] | 741 | } |
| 742 | |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 743 | // Write the count of response data. |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 744 | uint8_t returnCount; |
| 745 | if ((offset + readCount) <= size) |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 746 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 747 | returnCount = readCount; |
Nagaraju Goruganti | 7f2d7c9 | 2018-03-21 11:18:30 -0500 | [diff] [blame] | 748 | } |
| 749 | else |
| 750 | { |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 751 | returnCount = size - offset; |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 752 | } |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 753 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 754 | std::vector<uint8_t> fruData((fruArea.begin() + offset), |
| 755 | (fruArea.begin() + offset + returnCount)); |
Ratan Gupta | 2848d60 | 2018-01-31 20:39:20 +0530 | [diff] [blame] | 756 | |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 757 | return ipmi::responseSuccess(returnCount, fruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 758 | } |
| 759 | catch (const InternalFailure& e) |
| 760 | { |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 761 | log<level::ERR>(e.what()); |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 762 | return ipmi::responseUnspecifiedError(); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 763 | } |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 764 | } |
| 765 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 766 | ipmi::RspType<uint8_t, // SDR version |
| 767 | uint16_t, // record count LS first |
| 768 | uint16_t, // free space in bytes, LS first |
| 769 | uint32_t, // addition timestamp LS first |
| 770 | uint32_t, // deletion timestamp LS first |
| 771 | uint8_t> // operation Support |
| 772 | ipmiGetRepositoryInfo() |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 773 | { |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 774 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 775 | constexpr uint8_t sdrVersion = 0x51; |
| 776 | constexpr uint16_t freeSpace = 0xFFFF; |
| 777 | constexpr uint32_t additionTimestamp = 0x0; |
| 778 | constexpr uint32_t deletionTimestamp = 0x0; |
| 779 | constexpr uint8_t operationSupport = 0; |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 780 | |
Patrick Venture | db0cbe6 | 2019-09-09 14:47:22 -0700 | [diff] [blame] | 781 | uint16_t records = frus.size() + ipmi::sensor::sensors.size(); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 782 | |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 783 | return ipmi::responseSuccess(sdrVersion, records, freeSpace, |
| 784 | additionTimestamp, deletionTimestamp, |
| 785 | operationSupport); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 786 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 787 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 788 | void register_netfn_storage_functions() |
| 789 | { |
Lei YU | d9e5766 | 2021-09-14 18:06:28 +0800 | [diff] [blame^] | 790 | initSELCache(); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 791 | // <Get SEL Info> |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 792 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 793 | ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User, |
| 794 | ipmiStorageGetSelInfo); |
Tom Joseph | 6f7deaa | 2017-06-30 19:03:54 +0530 | [diff] [blame] | 795 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 796 | // <Get SEL Time> |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 797 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 798 | ipmi::storage::cmdGetSelTime, ipmi::Privilege::User, |
| 799 | ipmiStorageGetSelTime); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 800 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 801 | // <Set SEL Time> |
jayaprakash Mutyala | db2e8c4 | 2019-05-03 01:38:01 +0000 | [diff] [blame] | 802 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 803 | ipmi::storage::cmdSetSelTime, |
| 804 | ipmi::Privilege::Operator, ipmiStorageSetSelTime); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 805 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 806 | // <Reserve SEL> |
jayaprakash Mutyala | b755772 | 2019-05-02 21:13:30 +0000 | [diff] [blame] | 807 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 808 | ipmi::storage::cmdReserveSel, ipmi::Privilege::User, |
| 809 | ipmiStorageReserveSel); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 810 | // <Get SEL Entry> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 811 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, |
| 812 | getSELEntry, PRIVILEGE_USER); |
Tom Joseph | a495339 | 2017-06-30 19:09:47 +0530 | [diff] [blame] | 813 | |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 814 | // <Delete SEL Entry> |
Pradeep Kumar | 00a18d0 | 2019-04-26 17:04:28 +0000 | [diff] [blame] | 815 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 816 | ipmi::storage::cmdDeleteSelEntry, |
| 817 | ipmi::Privilege::Operator, deleteSELEntry); |
Tom Joseph | 8f4a2aa | 2017-06-30 19:12:49 +0530 | [diff] [blame] | 818 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 819 | // <Add SEL Entry> |
anil kumar appana | 2c7db1d | 2019-05-28 11:20:19 +0000 | [diff] [blame] | 820 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 821 | ipmi::storage::cmdAddSelEntry, |
| 822 | ipmi::Privilege::Operator, ipmiStorageAddSEL); |
| 823 | |
Tom Joseph | 2f05bb5 | 2017-06-30 19:14:49 +0530 | [diff] [blame] | 824 | // <Clear SEL> |
Pradeep Kumar | 4a5a99a | 2019-04-26 15:22:39 +0000 | [diff] [blame] | 825 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 826 | ipmi::storage::cmdClearSel, ipmi::Privilege::Operator, |
| 827 | clearSEL); |
| 828 | |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 829 | // <Get FRU Inventory Area Info> |
Pradeep Kumar | b0c794d | 2019-05-02 13:09:14 +0000 | [diff] [blame] | 830 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 831 | ipmi::storage::cmdGetFruInventoryAreaInfo, |
| 832 | ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo); |
Marri Devender Rao | fa7b4e2 | 2017-07-03 00:52:20 -0500 | [diff] [blame] | 833 | |
Jason M. Bills | b5248c9 | 2019-06-24 15:53:08 -0700 | [diff] [blame] | 834 | // <READ FRU Data> |
anil kumar appana | 5b7c326 | 2019-05-27 18:10:23 +0000 | [diff] [blame] | 835 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 836 | ipmi::storage::cmdReadFruData, |
| 837 | ipmi::Privilege::Operator, ipmiStorageReadFruData); |
Marri Devender Rao | cac383b | 2017-07-03 13:24:27 -0500 | [diff] [blame] | 838 | |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 839 | // <Get Repository Info> |
Pradeep Kumar | b60e840 | 2019-05-06 15:17:01 +0000 | [diff] [blame] | 840 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 841 | ipmi::storage::cmdGetSdrRepositoryInfo, |
| 842 | ipmi::Privilege::User, ipmiGetRepositoryInfo); |
Dhruvaraj Subhashchandran | e66c3b0 | 2018-02-07 01:21:56 -0600 | [diff] [blame] | 843 | |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 844 | // <Reserve SDR Repository> |
jayaprakash Mutyala | d957823 | 2019-05-13 20:22:50 +0000 | [diff] [blame] | 845 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage, |
| 846 | ipmi::storage::cmdReserveSdrRepository, |
| 847 | ipmi::Privilege::User, ipmiSensorReserveSdr); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 848 | |
| 849 | // <Get SDR> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 850 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr, |
| 851 | ipmi_sen_get_sdr, PRIVILEGE_USER); |
Tom Joseph | 5ca5095 | 2018-02-22 00:33:38 +0530 | [diff] [blame] | 852 | |
Marri Devender Rao | 908f750 | 2017-07-10 01:49:54 -0500 | [diff] [blame] | 853 | ipmi::fru::registerCallbackHandler(); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 854 | return; |
| 855 | } |