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