blob: bd2c6e17d1ee68ff35a71fecd536044bd51eb1c7 [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,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053017 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 Vovchenko8f7a6f62017-08-17 00:31:14 +030022 GET_MGMNT_CTRL_ID_STR = 0x09,
23 SET_MGMNT_CTRL_ID_STR = 0x0A,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060024 GET_TEMP_READINGS = 0x10,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053025};
26
Tom Josephbe5eaa12017-07-12 19:54:44 +053027static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
28static constexpr auto assetTagIntf =
29 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
30static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030031static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
32static constexpr auto networkConfigObj =
33 "/xyz/openbmc_project/network/config";
34static constexpr auto networkConfigIntf =
35 "xyz.openbmc_project.Network.SystemConfiguration";
36static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060037static constexpr auto temperatureSensorType = 0x01;
Tom Josephbe5eaa12017-07-12 19:54:44 +053038
39namespace 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 Kodihalliee717d72018-01-24 04:53:09 -060049namespace temp_readings
50{
51 static constexpr auto maxDataSets = 8;
52 static constexpr auto maxInstances = 255;
Deepak Kodihalli138e0182018-02-02 07:17:02 -060053 static constexpr auto maxTemp = 127; // degrees C
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -060054 static constexpr auto configFile =
55 "/usr/share/ipmi-providers/dcmi_temp_readings.json";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060056
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 Kodihallib1e8fba2018-01-24 04:57:10 -060076 using Value = uint8_t;
77 using Sign = bool;
78 using Temperature = std::tuple<Value, Sign>;
79 using Json = nlohmann::json;
Deepak Kodihalliee717d72018-01-24 04:53:09 -060080}
81
Tom Joseph6f6dd4d2017-07-12 20:07:11 +053082static constexpr auto groupExtId = 0xDC;
83
84static constexpr auto assetTagMaxOffset = 62;
85static constexpr auto assetTagMaxSize = 63;
86static constexpr auto maxBytes = 16;
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030087static constexpr size_t maxCtrlIdStrLen = 63;
Tom Joseph6f6dd4d2017-07-12 20:07:11 +053088
89/** @struct GetAssetTagRequest
90 *
91 * DCMI payload for Get Asset Tag command request.
92 */
93struct 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 */
104struct GetAssetTagResponse
105{
106 uint8_t groupID; //!< Group extension identification.
107 uint8_t tagLength; //!< Total asset tag length.
108} __attribute__((packed));
109
Tom Joseph545dd232017-07-12 20:20:49 +0530110/** @struct SetAssetTagRequest
111 *
112 * DCMI payload for Set Asset Tag command request.
113 */
114struct 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 */
125struct SetAssetTagResponse
126{
127 uint8_t groupID; //!< Group extension identification.
128 uint8_t tagLength; //!< Total asset tag length.
129} __attribute__((packed));
130
Tom Josephbe5eaa12017-07-12 19:54:44 +0530131/** @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 */
139void 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 */
145std::string readAssetTag();
146
Tom Josephbe5b9892017-07-15 00:55:23 +0530147/** @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 */
151void writeAssetTag(const std::string& assetTag);
152
Tom Josephb9d86f42017-07-26 18:03:47 +0530153/** @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 */
159uint32_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 */
168bool getPcapEnabled(sdbusplus::bus::bus& bus);
169
170/** @struct GetPowerLimitRequest
171 *
172 * DCMI payload for Get Power Limit command request.
173 */
174struct 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 */
184struct 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 Joseph46fa37d2017-07-26 18:11:55 +0530195/** @brief Set the power cap value
196 *
197 * @param[in] bus - dbus connection
198 * @param[in] powerCap - power cap value
199 */
200void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap);
201
202/** @struct SetPowerLimitRequest
203 *
204 * DCMI payload for Set Power Limit command request.
205 */
206struct 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 */
222struct SetPowerLimitResponse
223{
224 uint8_t groupID; //!< Group extension identification.
225} __attribute__((packed));
226
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530227/** @brief Enable or disable the power capping
228 *
229 * @param[in] bus - dbus connection
230 * @param[in] enabled - enable/disable
231 */
232void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled);
233
234/** @struct ApplyPowerLimitRequest
235 *
236 * DCMI payload for Activate/Deactivate Power Limit command request.
237 */
238struct 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 */
249struct ApplyPowerLimitResponse
250{
251 uint8_t groupID; //!< Group extension identification.
252} __attribute__((packed));
253
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300254/** @struct GetMgmntCtrlIdStrRequest
255 *
256 * DCMI payload for Get Management Controller Identifier String cmd request.
257 */
258struct 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 */
269struct 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 */
280struct 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 */
292struct SetMgmntCtrlIdStrResponse
293{
294 uint8_t groupID; //!< Group extension identification.
295 uint8_t offset; //!< Last Offset Written.
296} __attribute__((packed));
297
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600298/** @enum DCMICapParameters
299 *
300 * DCMI Capability parameters
301 */
302enum 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 */
314struct 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 */
324struct 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 */
337struct 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
345using DCMICapList = std::vector<DCMICap>;
346
347/** @struct DCMICapEntry
348 *
349 * DCMI capabilities list and size for each parameter.
350 */
351struct DCMICapEntry
352{
353 uint8_t size; //!< Size of capability array in bytes.
354 DCMICapList capList; //!< List of capabilities for a parameter.
355};
356
357using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>;
358
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600359/** @struct GetTempReadingsRequest
360 *
361 * DCMI payload for Get Temperature Readings request
362 */
363struct 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 */
376struct 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
383namespace temp_readings
384{
Deepak Kodihallib1e8fba2018-01-24 04:57:10 -0600385 /** @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 Kodihalliee717d72018-01-24 04:53:09 -0600403 /** @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 Josephbe5eaa12017-07-12 19:54:44 +0530430} // namespace dcmi
431
432#endif