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