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