Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 1 | #ifndef __HOST_IPMI_DCMI_HANDLER_H__ |
| 2 | #define __HOST_IPMI_DCMI_HANDLER_H__ |
| 3 | |
| 4 | #include <map> |
| 5 | #include <string> |
| 6 | #include <vector> |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 8 | #include "nlohmann/json.hpp" |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 9 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 10 | namespace dcmi |
| 11 | { |
| 12 | |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 13 | enum Commands |
| 14 | { |
| 15 | // Get capability bits |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 16 | GET_CAPABILITIES = 0x01, |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 17 | GET_POWER_LIMIT = 0x03, |
| 18 | SET_POWER_LIMIT = 0x04, |
| 19 | APPLY_POWER_LIMIT = 0x05, |
| 20 | GET_ASSET_TAG = 0x06, |
| 21 | SET_ASSET_TAG = 0x08, |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 22 | GET_MGMNT_CTRL_ID_STR = 0x09, |
| 23 | SET_MGMNT_CTRL_ID_STR = 0x0A, |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 24 | GET_TEMP_READINGS = 0x10, |
Ratan Gupta | 11ddbd2 | 2017-08-05 11:59:39 +0530 | [diff] [blame] | 25 | }; |
| 26 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 27 | static constexpr auto propIntf = "org.freedesktop.DBus.Properties"; |
| 28 | static constexpr auto assetTagIntf = |
| 29 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
| 30 | static constexpr auto assetTagProp = "AssetTag"; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 31 | static constexpr auto networkServiceName = "xyz.openbmc_project.Network"; |
| 32 | static constexpr auto networkConfigObj = |
| 33 | "/xyz/openbmc_project/network/config"; |
| 34 | static constexpr auto networkConfigIntf = |
| 35 | "xyz.openbmc_project.Network.SystemConfiguration"; |
| 36 | static constexpr auto hostNameProp = "HostName"; |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 37 | static constexpr auto temperatureSensorType = 0x01; |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 38 | |
| 39 | namespace assettag |
| 40 | { |
| 41 | |
| 42 | using ObjectPath = std::string; |
| 43 | using Service = std::string; |
| 44 | using Interfaces = std::vector<std::string>; |
| 45 | using ObjectTree = std::map<ObjectPath, std::map<Service, Interfaces>>; |
| 46 | |
| 47 | } //namespace assettag |
| 48 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 49 | namespace temp_readings |
| 50 | { |
| 51 | static constexpr auto maxDataSets = 8; |
| 52 | static constexpr auto maxInstances = 255; |
Deepak Kodihalli | 138e018 | 2018-02-02 07:17:02 -0600 | [diff] [blame^] | 53 | static constexpr auto maxTemp = 127; // degrees C |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 54 | static constexpr auto configFile = |
| 55 | "/usr/share/ipmi-providers/dcmi_temp_readings.json"; |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 56 | |
| 57 | /** @struct Response |
| 58 | * |
| 59 | * DCMI payload for Get Temperature Readings response |
| 60 | */ |
| 61 | struct Response |
| 62 | { |
| 63 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 64 | uint8_t temperature: 7; //!< Temperature reading in Celsius |
| 65 | uint8_t sign: 1; //!< Sign bit |
| 66 | #endif |
| 67 | #if BYTE_ORDER == BIG_ENDIAN |
| 68 | uint8_t sign: 1; //!< Sign bit |
| 69 | uint8_t temperature: 7; //!< Temperature reading in Celsius |
| 70 | #endif |
| 71 | uint8_t instance; //!< Entity instance number |
| 72 | } __attribute__((packed)); |
| 73 | |
| 74 | using ResponseList = std::vector<Response>; |
| 75 | using NumInstances = size_t; |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 76 | using Value = uint8_t; |
| 77 | using Sign = bool; |
| 78 | using Temperature = std::tuple<Value, Sign>; |
| 79 | using Json = nlohmann::json; |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 80 | } |
| 81 | |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 82 | static constexpr auto groupExtId = 0xDC; |
| 83 | |
| 84 | static constexpr auto assetTagMaxOffset = 62; |
| 85 | static constexpr auto assetTagMaxSize = 63; |
| 86 | static constexpr auto maxBytes = 16; |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 87 | static constexpr size_t maxCtrlIdStrLen = 63; |
Tom Joseph | 6f6dd4d | 2017-07-12 20:07:11 +0530 | [diff] [blame] | 88 | |
| 89 | /** @struct GetAssetTagRequest |
| 90 | * |
| 91 | * DCMI payload for Get Asset Tag command request. |
| 92 | */ |
| 93 | struct GetAssetTagRequest |
| 94 | { |
| 95 | uint8_t groupID; //!< Group extension identification. |
| 96 | uint8_t offset; //!< Offset to read. |
| 97 | uint8_t bytes; //!< Number of bytes to read. |
| 98 | } __attribute__((packed)); |
| 99 | |
| 100 | /** @struct GetAssetTagResponse |
| 101 | * |
| 102 | * DCMI payload for Get Asset Tag command response. |
| 103 | */ |
| 104 | struct GetAssetTagResponse |
| 105 | { |
| 106 | uint8_t groupID; //!< Group extension identification. |
| 107 | uint8_t tagLength; //!< Total asset tag length. |
| 108 | } __attribute__((packed)); |
| 109 | |
Tom Joseph | 545dd23 | 2017-07-12 20:20:49 +0530 | [diff] [blame] | 110 | /** @struct SetAssetTagRequest |
| 111 | * |
| 112 | * DCMI payload for Set Asset Tag command request. |
| 113 | */ |
| 114 | struct SetAssetTagRequest |
| 115 | { |
| 116 | uint8_t groupID; //!< Group extension identification. |
| 117 | uint8_t offset; //!< Offset to write. |
| 118 | uint8_t bytes; //!< Number of bytes to write. |
| 119 | } __attribute__((packed)); |
| 120 | |
| 121 | /** @struct SetAssetTagResponse |
| 122 | * |
| 123 | * DCMI payload for Set Asset Tag command response. |
| 124 | */ |
| 125 | struct SetAssetTagResponse |
| 126 | { |
| 127 | uint8_t groupID; //!< Group extension identification. |
| 128 | uint8_t tagLength; //!< Total asset tag length. |
| 129 | } __attribute__((packed)); |
| 130 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 131 | /** @brief Read the object tree to fetch the object path that implemented the |
| 132 | * Asset tag interface. |
| 133 | * |
| 134 | * @param[in,out] objectTree - object tree |
| 135 | * |
| 136 | * @return On success return the object tree with the object path that |
| 137 | * implemented the AssetTag interface. |
| 138 | */ |
| 139 | void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree); |
| 140 | |
| 141 | /** @brief Read the asset tag of the server |
| 142 | * |
| 143 | * @return On success return the asset tag. |
| 144 | */ |
| 145 | std::string readAssetTag(); |
| 146 | |
Tom Joseph | be5b989 | 2017-07-15 00:55:23 +0530 | [diff] [blame] | 147 | /** @brief Write the asset tag to the asset tag DBUS property |
| 148 | * |
| 149 | * @param[in] assetTag - Asset Tag to be written to the property. |
| 150 | */ |
| 151 | void writeAssetTag(const std::string& assetTag); |
| 152 | |
Tom Joseph | b9d86f4 | 2017-07-26 18:03:47 +0530 | [diff] [blame] | 153 | /** @brief Read the current power cap value |
| 154 | * |
| 155 | * @param[in] bus - dbus connection |
| 156 | * |
| 157 | * @return On success return the power cap value. |
| 158 | */ |
| 159 | uint32_t getPcap(sdbusplus::bus::bus& bus); |
| 160 | |
| 161 | /** @brief Check if the power capping is enabled |
| 162 | * |
| 163 | * @param[in] bus - dbus connection |
| 164 | * |
| 165 | * @return true if the powerCap is enabled and false if the powercap |
| 166 | * is disabled. |
| 167 | */ |
| 168 | bool getPcapEnabled(sdbusplus::bus::bus& bus); |
| 169 | |
| 170 | /** @struct GetPowerLimitRequest |
| 171 | * |
| 172 | * DCMI payload for Get Power Limit command request. |
| 173 | */ |
| 174 | struct GetPowerLimitRequest |
| 175 | { |
| 176 | uint8_t groupID; //!< Group extension identification. |
| 177 | uint16_t reserved; //!< Reserved |
| 178 | } __attribute__((packed)); |
| 179 | |
| 180 | /** @struct GetPowerLimitResponse |
| 181 | * |
| 182 | * DCMI payload for Get Power Limit command response. |
| 183 | */ |
| 184 | struct GetPowerLimitResponse |
| 185 | { |
| 186 | uint8_t groupID; //!< Group extension identification. |
| 187 | uint16_t reserved; //!< Reserved. |
| 188 | uint8_t exceptionAction; //!< Exception action. |
| 189 | uint16_t powerLimit; //!< Power limit requested in watts. |
| 190 | uint32_t correctionTime; //!< Correction time limit in milliseconds. |
| 191 | uint16_t reserved1; //!< Reserved. |
| 192 | uint16_t samplingPeriod; //!< Statistics sampling period in seconds. |
| 193 | } __attribute__((packed)); |
| 194 | |
Tom Joseph | 46fa37d | 2017-07-26 18:11:55 +0530 | [diff] [blame] | 195 | /** @brief Set the power cap value |
| 196 | * |
| 197 | * @param[in] bus - dbus connection |
| 198 | * @param[in] powerCap - power cap value |
| 199 | */ |
| 200 | void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap); |
| 201 | |
| 202 | /** @struct SetPowerLimitRequest |
| 203 | * |
| 204 | * DCMI payload for Set Power Limit command request. |
| 205 | */ |
| 206 | struct SetPowerLimitRequest |
| 207 | { |
| 208 | uint8_t groupID; //!< Group extension identification. |
| 209 | uint16_t reserved; //!< Reserved |
| 210 | uint8_t reserved1; //!< Reserved |
| 211 | uint8_t exceptionAction; //!< Exception action. |
| 212 | uint16_t powerLimit; //!< Power limit requested in watts. |
| 213 | uint32_t correctionTime; //!< Correction time limit in milliseconds. |
| 214 | uint16_t reserved2; //!< Reserved. |
| 215 | uint16_t samplingPeriod; //!< Statistics sampling period in seconds. |
| 216 | } __attribute__((packed)); |
| 217 | |
| 218 | /** @struct SetPowerLimitResponse |
| 219 | * |
| 220 | * DCMI payload for Set Power Limit command response. |
| 221 | */ |
| 222 | struct SetPowerLimitResponse |
| 223 | { |
| 224 | uint8_t groupID; //!< Group extension identification. |
| 225 | } __attribute__((packed)); |
| 226 | |
Tom Joseph | 6c8d51b | 2017-07-26 18:18:06 +0530 | [diff] [blame] | 227 | /** @brief Enable or disable the power capping |
| 228 | * |
| 229 | * @param[in] bus - dbus connection |
| 230 | * @param[in] enabled - enable/disable |
| 231 | */ |
| 232 | void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled); |
| 233 | |
| 234 | /** @struct ApplyPowerLimitRequest |
| 235 | * |
| 236 | * DCMI payload for Activate/Deactivate Power Limit command request. |
| 237 | */ |
| 238 | struct ApplyPowerLimitRequest |
| 239 | { |
| 240 | uint8_t groupID; //!< Group extension identification. |
| 241 | uint8_t powerLimitAction; //!< Power limit activation |
| 242 | uint16_t reserved; //!< Reserved |
| 243 | } __attribute__((packed)); |
| 244 | |
| 245 | /** @struct ApplyPowerLimitResponse |
| 246 | * |
| 247 | * DCMI payload for Acticate/Deactivate Power Limit command response. |
| 248 | */ |
| 249 | struct ApplyPowerLimitResponse |
| 250 | { |
| 251 | uint8_t groupID; //!< Group extension identification. |
| 252 | } __attribute__((packed)); |
| 253 | |
Vladislav Vovchenko | 8f7a6f6 | 2017-08-17 00:31:14 +0300 | [diff] [blame] | 254 | /** @struct GetMgmntCtrlIdStrRequest |
| 255 | * |
| 256 | * DCMI payload for Get Management Controller Identifier String cmd request. |
| 257 | */ |
| 258 | struct GetMgmntCtrlIdStrRequest |
| 259 | { |
| 260 | uint8_t groupID; //!< Group extension identification. |
| 261 | uint8_t offset; //!< Offset to read. |
| 262 | uint8_t bytes; //!< Number of bytes to read. |
| 263 | } __attribute__((packed)); |
| 264 | |
| 265 | /** @struct GetMgmntCtrlIdStrResponse |
| 266 | * |
| 267 | * DCMI payload for Get Management Controller Identifier String cmd response. |
| 268 | */ |
| 269 | struct GetMgmntCtrlIdStrResponse |
| 270 | { |
| 271 | uint8_t groupID; //!< Group extension identification. |
| 272 | uint8_t strLen; //!< ID string length. |
| 273 | char data[]; //!< ID string |
| 274 | } __attribute__((packed)); |
| 275 | |
| 276 | /** @struct SetMgmntCtrlIdStrRequest |
| 277 | * |
| 278 | * DCMI payload for Set Management Controller Identifier String cmd request. |
| 279 | */ |
| 280 | struct SetMgmntCtrlIdStrRequest |
| 281 | { |
| 282 | uint8_t groupID; //!< Group extension identification. |
| 283 | uint8_t offset; //!< Offset to write. |
| 284 | uint8_t bytes; //!< Number of bytes to read. |
| 285 | char data[]; //!< ID string |
| 286 | } __attribute__((packed)); |
| 287 | |
| 288 | /** @struct GetMgmntCtrlIdStrResponse |
| 289 | * |
| 290 | * DCMI payload for Get Management Controller Identifier String cmd response. |
| 291 | */ |
| 292 | struct SetMgmntCtrlIdStrResponse |
| 293 | { |
| 294 | uint8_t groupID; //!< Group extension identification. |
| 295 | uint8_t offset; //!< Last Offset Written. |
| 296 | } __attribute__((packed)); |
| 297 | |
Dhruvaraj Subhashchandran | e29be41 | 2018-01-16 05:11:56 -0600 | [diff] [blame] | 298 | /** @enum DCMICapParameters |
| 299 | * |
| 300 | * DCMI Capability parameters |
| 301 | */ |
| 302 | enum class DCMICapParameters |
| 303 | { |
| 304 | SUPPORTED_DCMI_CAPS = 0x01, //!< Supported DCMI Capabilities |
| 305 | MANDATORY_PLAT_ATTRIBUTES = 0x02, //!< Mandatory Platform Attributes |
| 306 | OPTIONAL_PLAT_ATTRIBUTES = 0x03, //!< Optional Platform Attributes |
| 307 | MANAGEABILITY_ACCESS_ATTRIBUTES = 0x04, //!< Manageability Access Attributes |
| 308 | }; |
| 309 | |
| 310 | /** @struct GetDCMICapRequest |
| 311 | * |
| 312 | * DCMI payload for Get capabilities cmd request. |
| 313 | */ |
| 314 | struct GetDCMICapRequest |
| 315 | { |
| 316 | uint8_t groupID; //!< Group extension identification. |
| 317 | uint8_t param; //!< Capability parameter selector. |
| 318 | } __attribute__((packed)); |
| 319 | |
| 320 | /** @struct GetDCMICapRequest |
| 321 | * |
| 322 | * DCMI payload for Get capabilities cmd response. |
| 323 | */ |
| 324 | struct GetDCMICapResponse |
| 325 | { |
| 326 | uint8_t groupID; //!< Group extension identification. |
| 327 | uint8_t major; //!< DCMI Specification Conformance - major ver |
| 328 | uint8_t minor; //!< DCMI Specification Conformance - minor ver |
| 329 | uint8_t paramRevision; //!< Parameter Revision = 02h |
| 330 | uint8_t data[]; //!< Capability array |
| 331 | } __attribute__((packed)); |
| 332 | |
| 333 | /** @struct DCMICap |
| 334 | * |
| 335 | * DCMI capabilities protocol info. |
| 336 | */ |
| 337 | struct DCMICap |
| 338 | { |
| 339 | std::string name; //!< Name of DCMI capability. |
| 340 | uint8_t bytePosition; //!< Starting byte number from DCMI spec. |
| 341 | uint8_t position; //!< bit position from the DCMI spec. |
| 342 | uint8_t length; //!< Length of the value from DCMI spec. |
| 343 | }; |
| 344 | |
| 345 | using DCMICapList = std::vector<DCMICap>; |
| 346 | |
| 347 | /** @struct DCMICapEntry |
| 348 | * |
| 349 | * DCMI capabilities list and size for each parameter. |
| 350 | */ |
| 351 | struct DCMICapEntry |
| 352 | { |
| 353 | uint8_t size; //!< Size of capability array in bytes. |
| 354 | DCMICapList capList; //!< List of capabilities for a parameter. |
| 355 | }; |
| 356 | |
| 357 | using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>; |
| 358 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 359 | /** @struct GetTempReadingsRequest |
| 360 | * |
| 361 | * DCMI payload for Get Temperature Readings request |
| 362 | */ |
| 363 | struct GetTempReadingsRequest |
| 364 | { |
| 365 | uint8_t groupID; //!< Group extension identification. |
| 366 | uint8_t sensorType; //!< Type of the sensor |
| 367 | uint8_t entityId; //!< Entity ID |
| 368 | uint8_t entityInstance; //!< Entity Instance (0 means all instances) |
| 369 | uint8_t instanceStart; //!< Instance start (used if instance is 0) |
| 370 | } __attribute__((packed)); |
| 371 | |
| 372 | /** @struct GetTempReadingsResponse |
| 373 | * |
| 374 | * DCMI header for Get Temperature Readings response |
| 375 | */ |
| 376 | struct GetTempReadingsResponseHdr |
| 377 | { |
| 378 | uint8_t groupID; //!< Group extension identification. |
| 379 | uint8_t numInstances; //!< No. of instances for requested id |
| 380 | uint8_t numDataSets; //!< No. of sets of temperature data |
| 381 | } __attribute__((packed)); |
| 382 | |
| 383 | namespace temp_readings |
| 384 | { |
Deepak Kodihalli | b1e8fba | 2018-01-24 04:57:10 -0600 | [diff] [blame] | 385 | /** @brief Read temperature from a d-bus object, scale it as per dcmi |
| 386 | * get temperature reading requirements. |
| 387 | * |
| 388 | * @param[in] dbusService - the D-Bus service |
| 389 | * @param[in] dbusPath - the D-Bus path |
| 390 | * |
| 391 | * @return A temperature reading |
| 392 | */ |
| 393 | Temperature readTemp(const std::string& dbusService, |
| 394 | const std::string& dbusPath); |
| 395 | |
| 396 | /** @brief Parse out JSON config file containing information |
| 397 | * related to temperature readings. |
| 398 | * |
| 399 | * @return A json object |
| 400 | */ |
| 401 | Json parseConfig(); |
| 402 | |
Deepak Kodihalli | ee717d7 | 2018-01-24 04:53:09 -0600 | [diff] [blame] | 403 | /** @brief Read temperatures and fill up DCMI response for the Get |
| 404 | * Temperature Readings command. This looks at a specific |
| 405 | * instance. |
| 406 | * |
| 407 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 408 | * @param[in] instance - A non-zero Entity instance number |
| 409 | * |
| 410 | * @return A tuple, containing a temperature reading and the |
| 411 | * number of instances. |
| 412 | */ |
| 413 | std::tuple<Response, NumInstances> read (const std::string& type, |
| 414 | uint8_t instance); |
| 415 | |
| 416 | /** @brief Read temperatures and fill up DCMI response for the Get |
| 417 | * Temperature Readings command. This looks at a range of |
| 418 | * instances. |
| 419 | * |
| 420 | * @param[in] type - one of "inlet", "cpu", "baseboard" |
| 421 | * @param[in] instanceStart - Entity instance start index |
| 422 | * |
| 423 | * @return A tuple, containing a list of temperature readings and the |
| 424 | * number of instances. |
| 425 | */ |
| 426 | std::tuple<ResponseList, NumInstances> readAll(const std::string& type, |
| 427 | uint8_t instanceStart); |
| 428 | } |
| 429 | |
Tom Joseph | be5eaa1 | 2017-07-12 19:54:44 +0530 | [diff] [blame] | 430 | } // namespace dcmi |
| 431 | |
| 432 | #endif |