blob: e2a4c10d2c1d8f54a2ab7c8e2f384a019bf524eb [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
Deepak Kodihalli0b459552018-02-06 06:25:12 -060013using NumInstances = size_t;
14using Json = nlohmann::json;
15
Ratan Gupta11ddbd22017-08-05 11:59:39 +053016enum Commands
17{
18 // Get capability bits
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -060019 GET_CAPABILITIES = 0x01,
Marri Devender Rao66c5fda2018-01-18 10:48:37 -060020 GET_POWER_READING = 0x02,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053021 GET_POWER_LIMIT = 0x03,
22 SET_POWER_LIMIT = 0x04,
23 APPLY_POWER_LIMIT = 0x05,
24 GET_ASSET_TAG = 0x06,
Deepak Kodihalli0b459552018-02-06 06:25:12 -060025 GET_SENSOR_INFO = 0x07,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053026 SET_ASSET_TAG = 0x08,
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030027 GET_MGMNT_CTRL_ID_STR = 0x09,
28 SET_MGMNT_CTRL_ID_STR = 0x0A,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060029 GET_TEMP_READINGS = 0x10,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053030};
31
Tom Josephbe5eaa12017-07-12 19:54:44 +053032static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
33static constexpr auto assetTagIntf =
34 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
35static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030036static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
37static constexpr auto networkConfigObj =
38 "/xyz/openbmc_project/network/config";
39static constexpr auto networkConfigIntf =
40 "xyz.openbmc_project.Network.SystemConfiguration";
41static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060042static constexpr auto temperatureSensorType = 0x01;
Deepak Kodihalli0b459552018-02-06 06:25:12 -060043static constexpr auto maxInstances = 255;
44static constexpr auto configFile =
45 "/usr/share/ipmi-providers/dcmi_sensors.json";
Tom Josephbe5eaa12017-07-12 19:54:44 +053046
47namespace assettag
48{
49
50 using ObjectPath = std::string;
51 using Service = std::string;
52 using Interfaces = std::vector<std::string>;
53 using ObjectTree = std::map<ObjectPath, std::map<Service, Interfaces>>;
54
55} //namespace assettag
56
Deepak Kodihalliee717d72018-01-24 04:53:09 -060057namespace temp_readings
58{
59 static constexpr auto maxDataSets = 8;
Deepak Kodihalli138e0182018-02-02 07:17:02 -060060 static constexpr auto maxTemp = 127; // degrees C
Deepak Kodihalliee717d72018-01-24 04:53:09 -060061
62 /** @struct Response
63 *
64 * DCMI payload for Get Temperature Readings response
65 */
66 struct Response
67 {
68#if BYTE_ORDER == LITTLE_ENDIAN
69 uint8_t temperature: 7; //!< Temperature reading in Celsius
70 uint8_t sign: 1; //!< Sign bit
71#endif
72#if BYTE_ORDER == BIG_ENDIAN
73 uint8_t sign: 1; //!< Sign bit
74 uint8_t temperature: 7; //!< Temperature reading in Celsius
75#endif
76 uint8_t instance; //!< Entity instance number
77 } __attribute__((packed));
78
79 using ResponseList = std::vector<Response>;
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -060080 using Value = uint8_t;
81 using Sign = bool;
82 using Temperature = std::tuple<Value, Sign>;
Deepak Kodihalliee717d72018-01-24 04:53:09 -060083}
84
Deepak Kodihalli0b459552018-02-06 06:25:12 -060085namespace sensor_info
86{
87 static constexpr auto maxRecords = 8;
88
89 /** @struct Response
90 *
91 * DCMI payload for Get Sensor Info response
92 */
93 struct Response
94 {
95 uint8_t recordIdLsb; //!< SDR record id LS byte
96 uint8_t recordIdMsb; //!< SDR record id MS byte
97 } __attribute__((packed));
98
99 using ResponseList = std::vector<Response>;
100} // namespace sensor_info
101
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530102static constexpr auto groupExtId = 0xDC;
103
104static constexpr auto assetTagMaxOffset = 62;
105static constexpr auto assetTagMaxSize = 63;
106static constexpr auto maxBytes = 16;
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300107static constexpr size_t maxCtrlIdStrLen = 63;
Tom Joseph6f6dd4d2017-07-12 20:07:11 +0530108
109/** @struct GetAssetTagRequest
110 *
111 * DCMI payload for Get Asset Tag command request.
112 */
113struct GetAssetTagRequest
114{
115 uint8_t groupID; //!< Group extension identification.
116 uint8_t offset; //!< Offset to read.
117 uint8_t bytes; //!< Number of bytes to read.
118} __attribute__((packed));
119
120/** @struct GetAssetTagResponse
121 *
122 * DCMI payload for Get Asset Tag command response.
123 */
124struct GetAssetTagResponse
125{
126 uint8_t groupID; //!< Group extension identification.
127 uint8_t tagLength; //!< Total asset tag length.
128} __attribute__((packed));
129
Tom Joseph545dd232017-07-12 20:20:49 +0530130/** @struct SetAssetTagRequest
131 *
132 * DCMI payload for Set Asset Tag command request.
133 */
134struct SetAssetTagRequest
135{
136 uint8_t groupID; //!< Group extension identification.
137 uint8_t offset; //!< Offset to write.
138 uint8_t bytes; //!< Number of bytes to write.
139} __attribute__((packed));
140
141/** @struct SetAssetTagResponse
142 *
143 * DCMI payload for Set Asset Tag command response.
144 */
145struct SetAssetTagResponse
146{
147 uint8_t groupID; //!< Group extension identification.
148 uint8_t tagLength; //!< Total asset tag length.
149} __attribute__((packed));
150
Tom Josephbe5eaa12017-07-12 19:54:44 +0530151/** @brief Read the object tree to fetch the object path that implemented the
152 * Asset tag interface.
153 *
154 * @param[in,out] objectTree - object tree
155 *
156 * @return On success return the object tree with the object path that
157 * implemented the AssetTag interface.
158 */
159void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree);
160
161/** @brief Read the asset tag of the server
162 *
163 * @return On success return the asset tag.
164 */
165std::string readAssetTag();
166
Tom Josephbe5b9892017-07-15 00:55:23 +0530167/** @brief Write the asset tag to the asset tag DBUS property
168 *
169 * @param[in] assetTag - Asset Tag to be written to the property.
170 */
171void writeAssetTag(const std::string& assetTag);
172
Tom Josephb9d86f42017-07-26 18:03:47 +0530173/** @brief Read the current power cap value
174 *
175 * @param[in] bus - dbus connection
176 *
177 * @return On success return the power cap value.
178 */
179uint32_t getPcap(sdbusplus::bus::bus& bus);
180
181/** @brief Check if the power capping is enabled
182 *
183 * @param[in] bus - dbus connection
184 *
185 * @return true if the powerCap is enabled and false if the powercap
186 * is disabled.
187 */
188bool getPcapEnabled(sdbusplus::bus::bus& bus);
189
190/** @struct GetPowerLimitRequest
191 *
192 * DCMI payload for Get Power Limit command request.
193 */
194struct GetPowerLimitRequest
195{
196 uint8_t groupID; //!< Group extension identification.
197 uint16_t reserved; //!< Reserved
198} __attribute__((packed));
199
200/** @struct GetPowerLimitResponse
201 *
202 * DCMI payload for Get Power Limit command response.
203 */
204struct GetPowerLimitResponse
205{
206 uint8_t groupID; //!< Group extension identification.
207 uint16_t reserved; //!< Reserved.
208 uint8_t exceptionAction; //!< Exception action.
209 uint16_t powerLimit; //!< Power limit requested in watts.
210 uint32_t correctionTime; //!< Correction time limit in milliseconds.
211 uint16_t reserved1; //!< Reserved.
212 uint16_t samplingPeriod; //!< Statistics sampling period in seconds.
213} __attribute__((packed));
214
Tom Joseph46fa37d2017-07-26 18:11:55 +0530215/** @brief Set the power cap value
216 *
217 * @param[in] bus - dbus connection
218 * @param[in] powerCap - power cap value
219 */
220void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap);
221
222/** @struct SetPowerLimitRequest
223 *
224 * DCMI payload for Set Power Limit command request.
225 */
226struct SetPowerLimitRequest
227{
228 uint8_t groupID; //!< Group extension identification.
229 uint16_t reserved; //!< Reserved
230 uint8_t reserved1; //!< Reserved
231 uint8_t exceptionAction; //!< Exception action.
232 uint16_t powerLimit; //!< Power limit requested in watts.
233 uint32_t correctionTime; //!< Correction time limit in milliseconds.
234 uint16_t reserved2; //!< Reserved.
235 uint16_t samplingPeriod; //!< Statistics sampling period in seconds.
236} __attribute__((packed));
237
238/** @struct SetPowerLimitResponse
239 *
240 * DCMI payload for Set Power Limit command response.
241 */
242struct SetPowerLimitResponse
243{
244 uint8_t groupID; //!< Group extension identification.
245} __attribute__((packed));
246
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530247/** @brief Enable or disable the power capping
248 *
249 * @param[in] bus - dbus connection
250 * @param[in] enabled - enable/disable
251 */
252void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled);
253
254/** @struct ApplyPowerLimitRequest
255 *
256 * DCMI payload for Activate/Deactivate Power Limit command request.
257 */
258struct ApplyPowerLimitRequest
259{
260 uint8_t groupID; //!< Group extension identification.
261 uint8_t powerLimitAction; //!< Power limit activation
262 uint16_t reserved; //!< Reserved
263} __attribute__((packed));
264
265/** @struct ApplyPowerLimitResponse
266 *
267 * DCMI payload for Acticate/Deactivate Power Limit command response.
268 */
269struct ApplyPowerLimitResponse
270{
271 uint8_t groupID; //!< Group extension identification.
272} __attribute__((packed));
273
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300274/** @struct GetMgmntCtrlIdStrRequest
275 *
276 * DCMI payload for Get Management Controller Identifier String cmd request.
277 */
278struct GetMgmntCtrlIdStrRequest
279{
280 uint8_t groupID; //!< Group extension identification.
281 uint8_t offset; //!< Offset to read.
282 uint8_t bytes; //!< Number of bytes to read.
283} __attribute__((packed));
284
285/** @struct GetMgmntCtrlIdStrResponse
286 *
287 * DCMI payload for Get Management Controller Identifier String cmd response.
288 */
289struct GetMgmntCtrlIdStrResponse
290{
291 uint8_t groupID; //!< Group extension identification.
292 uint8_t strLen; //!< ID string length.
293 char data[]; //!< ID string
294} __attribute__((packed));
295
296/** @struct SetMgmntCtrlIdStrRequest
297 *
298 * DCMI payload for Set Management Controller Identifier String cmd request.
299 */
300struct SetMgmntCtrlIdStrRequest
301{
302 uint8_t groupID; //!< Group extension identification.
303 uint8_t offset; //!< Offset to write.
304 uint8_t bytes; //!< Number of bytes to read.
305 char data[]; //!< ID string
306} __attribute__((packed));
307
308/** @struct GetMgmntCtrlIdStrResponse
309 *
310 * DCMI payload for Get Management Controller Identifier String cmd response.
311 */
312struct SetMgmntCtrlIdStrResponse
313{
314 uint8_t groupID; //!< Group extension identification.
315 uint8_t offset; //!< Last Offset Written.
316} __attribute__((packed));
317
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600318/** @enum DCMICapParameters
319 *
320 * DCMI Capability parameters
321 */
322enum class DCMICapParameters
323{
324 SUPPORTED_DCMI_CAPS = 0x01, //!< Supported DCMI Capabilities
325 MANDATORY_PLAT_ATTRIBUTES = 0x02, //!< Mandatory Platform Attributes
326 OPTIONAL_PLAT_ATTRIBUTES = 0x03, //!< Optional Platform Attributes
327 MANAGEABILITY_ACCESS_ATTRIBUTES = 0x04, //!< Manageability Access Attributes
328};
329
330/** @struct GetDCMICapRequest
331 *
332 * DCMI payload for Get capabilities cmd request.
333 */
334struct GetDCMICapRequest
335{
336 uint8_t groupID; //!< Group extension identification.
337 uint8_t param; //!< Capability parameter selector.
338} __attribute__((packed));
339
340/** @struct GetDCMICapRequest
341 *
342 * DCMI payload for Get capabilities cmd response.
343 */
344struct GetDCMICapResponse
345{
346 uint8_t groupID; //!< Group extension identification.
347 uint8_t major; //!< DCMI Specification Conformance - major ver
348 uint8_t minor; //!< DCMI Specification Conformance - minor ver
349 uint8_t paramRevision; //!< Parameter Revision = 02h
350 uint8_t data[]; //!< Capability array
351} __attribute__((packed));
352
353/** @struct DCMICap
354 *
355 * DCMI capabilities protocol info.
356 */
357struct DCMICap
358{
359 std::string name; //!< Name of DCMI capability.
360 uint8_t bytePosition; //!< Starting byte number from DCMI spec.
361 uint8_t position; //!< bit position from the DCMI spec.
362 uint8_t length; //!< Length of the value from DCMI spec.
363};
364
365using DCMICapList = std::vector<DCMICap>;
366
367/** @struct DCMICapEntry
368 *
369 * DCMI capabilities list and size for each parameter.
370 */
371struct DCMICapEntry
372{
373 uint8_t size; //!< Size of capability array in bytes.
374 DCMICapList capList; //!< List of capabilities for a parameter.
375};
376
377using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>;
378
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600379/** @struct GetTempReadingsRequest
380 *
381 * DCMI payload for Get Temperature Readings request
382 */
383struct GetTempReadingsRequest
384{
385 uint8_t groupID; //!< Group extension identification.
386 uint8_t sensorType; //!< Type of the sensor
387 uint8_t entityId; //!< Entity ID
388 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
389 uint8_t instanceStart; //!< Instance start (used if instance is 0)
390} __attribute__((packed));
391
392/** @struct GetTempReadingsResponse
393 *
394 * DCMI header for Get Temperature Readings response
395 */
396struct GetTempReadingsResponseHdr
397{
398 uint8_t groupID; //!< Group extension identification.
399 uint8_t numInstances; //!< No. of instances for requested id
400 uint8_t numDataSets; //!< No. of sets of temperature data
401} __attribute__((packed));
402
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600403/** @brief Parse out JSON config file containing information
404 * related to sensors.
405 *
406 * @return A json object
407 */
408Json parseSensorConfig();
409
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600410namespace temp_readings
411{
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600412 /** @brief Read temperature from a d-bus object, scale it as per dcmi
413 * get temperature reading requirements.
414 *
415 * @param[in] dbusService - the D-Bus service
416 * @param[in] dbusPath - the D-Bus path
417 *
418 * @return A temperature reading
419 */
420 Temperature readTemp(const std::string& dbusService,
421 const std::string& dbusPath);
422
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600423 /** @brief Read temperatures and fill up DCMI response for the Get
424 * Temperature Readings command. This looks at a specific
425 * instance.
426 *
427 * @param[in] type - one of "inlet", "cpu", "baseboard"
428 * @param[in] instance - A non-zero Entity instance number
429 *
430 * @return A tuple, containing a temperature reading and the
431 * number of instances.
432 */
433 std::tuple<Response, NumInstances> read (const std::string& type,
434 uint8_t instance);
435
436 /** @brief Read temperatures and fill up DCMI response for the Get
437 * Temperature Readings command. This looks at a range of
438 * instances.
439 *
440 * @param[in] type - one of "inlet", "cpu", "baseboard"
441 * @param[in] instanceStart - Entity instance start index
442 *
443 * @return A tuple, containing a list of temperature readings and the
444 * number of instances.
445 */
446 std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
447 uint8_t instanceStart);
448}
449
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600450namespace sensor_info
451{
Deepak Kodihallidd4cff12018-02-06 06:48:29 -0600452 /** @brief Create response from JSON config.
453 *
454 * @param[in] config - JSON config info about DCMI sensors
455 *
456 * @return Sensor info response
457 */
458 Response createFromJson(const Json& config);
459
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600460 /** @brief Read sensor info and fill up DCMI response for the Get
461 * Sensor Info command. This looks at a specific
462 * instance.
463 *
464 * @param[in] type - one of "inlet", "cpu", "baseboard"
465 * @param[in] instance - A non-zero Entity instance number
466 * @param[in] config - JSON config info about DCMI sensors
467 *
468 * @return A tuple, containing a sensor info response and
469 * number of instances.
470 */
471 std::tuple<Response, NumInstances> read(const std::string& type,
472 uint8_t instance,
473 const Json& config);
474
475 /** @brief Read sensor info and fill up DCMI response for the Get
476 * Sensor Info command. This looks at a range of
477 * instances.
478 *
479 * @param[in] type - one of "inlet", "cpu", "baseboard"
480 * @param[in] instanceStart - Entity instance start index
481 * @param[in] config - JSON config info about DCMI sensors
482 *
483 * @return A tuple, containing a list of sensor info responses and the
484 * number of instances.
485 */
486 std::tuple<ResponseList, NumInstances> readAll(const std::string& type,
487 uint8_t instanceStart,
488 const Json& config);
489} // namespace sensor_info
490
Marri Devender Rao66c5fda2018-01-18 10:48:37 -0600491/** @brief Read power reading from power reading sensor object
492 *
493 * @param[in] bus - dbus connection
494 *
495 * @return total power reading
496 */
497int64_t getPowerReading(sdbusplus::bus::bus& bus);
498
499/** @struct GetPowerReadingRequest
500 *
501 * DCMI Get Power Reading command request.
502 * Refer DCMI specification Version 1.1 Section 6.6.1
503 */
504struct GetPowerReadingRequest
505{
506 uint8_t groupID; //!< Group extension identification.
507 uint8_t mode; //!< Mode
508 uint8_t modeAttribute; //!< Mode Attributes
509} __attribute__((packed));
510
511/** @struct GetPowerReadingResponse
512 *
513 * DCMI Get Power Reading command response.
514 * Refer DCMI specification Version 1.1 Section 6.6.1
515 */
516struct GetPowerReadingResponse
517{
518 uint8_t groupID; //!< Group extension identification.
519 uint16_t currentPower; //!< Current power in watts
520 uint16_t minimumPower; //!< Minimum power over sampling duration
521 //!< in watts
522 uint16_t maximumPower; //!< Maximum power over sampling duration
523 //!< in watts
524 uint16_t averagePower; //!< Average power over sampling duration
525 //!< in watts
526 uint32_t timeStamp; //!< IPMI specification based time stamp
527 uint32_t timeFrame; //!< Statistics reporting time period in milli
528 //!< seconds.
529 uint8_t powerReadingState; //!< Power Reading State
530} __attribute__((packed));
531
Deepak Kodihalli0b459552018-02-06 06:25:12 -0600532/** @struct GetSensorInfoRequest
533 *
534 * DCMI payload for Get Sensor Info request
535 */
536struct GetSensorInfoRequest
537{
538 uint8_t groupID; //!< Group extension identification.
539 uint8_t sensorType; //!< Type of the sensor
540 uint8_t entityId; //!< Entity ID
541 uint8_t entityInstance; //!< Entity Instance (0 means all instances)
542 uint8_t instanceStart; //!< Instance start (used if instance is 0)
543} __attribute__((packed));
544
545/** @struct GetSensorInfoResponseHdr
546 *
547 * DCMI header for Get Sensor Info response
548 */
549struct GetSensorInfoResponseHdr
550{
551 uint8_t groupID; //!< Group extension identification.
552 uint8_t numInstances; //!< No. of instances for requested id
553 uint8_t numRecords; //!< No. of record ids in the response
554} __attribute__((packed));
555
Tom Josephbe5eaa12017-07-12 19:54:44 +0530556} // namespace dcmi
557
558#endif