blob: a7cfe8ad32b6f1e84983f4527c249fb91a05037b [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>
Tom Josephbe5eaa12017-07-12 19:54:44 +05308
Tom Josephbe5eaa12017-07-12 19:54:44 +05309namespace dcmi
10{
11
Ratan Gupta11ddbd22017-08-05 11:59:39 +053012enum Commands
13{
14 // Get capability bits
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -060015 GET_CAPABILITIES = 0x01,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053016 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 Vovchenko8f7a6f62017-08-17 00:31:14 +030021 GET_MGMNT_CTRL_ID_STR = 0x09,
22 SET_MGMNT_CTRL_ID_STR = 0x0A,
Deepak Kodihalliee717d72018-01-24 04:53:09 -060023 GET_TEMP_READINGS = 0x10,
Ratan Gupta11ddbd22017-08-05 11:59:39 +053024};
25
Tom Josephbe5eaa12017-07-12 19:54:44 +053026static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
27static constexpr auto assetTagIntf =
28 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
29static constexpr auto assetTagProp = "AssetTag";
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030030static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
31static constexpr auto networkConfigObj =
32 "/xyz/openbmc_project/network/config";
33static constexpr auto networkConfigIntf =
34 "xyz.openbmc_project.Network.SystemConfiguration";
35static constexpr auto hostNameProp = "HostName";
Deepak Kodihalliee717d72018-01-24 04:53:09 -060036static constexpr auto temperatureSensorType = 0x01;
Tom Josephbe5eaa12017-07-12 19:54:44 +053037
38namespace 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 Kodihalliee717d72018-01-24 04:53:09 -060048namespace 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 Joseph6f6dd4d2017-07-12 20:07:11 +053075static constexpr auto groupExtId = 0xDC;
76
77static constexpr auto assetTagMaxOffset = 62;
78static constexpr auto assetTagMaxSize = 63;
79static constexpr auto maxBytes = 16;
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +030080static constexpr size_t maxCtrlIdStrLen = 63;
Tom Joseph6f6dd4d2017-07-12 20:07:11 +053081
82/** @struct GetAssetTagRequest
83 *
84 * DCMI payload for Get Asset Tag command request.
85 */
86struct 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 */
97struct GetAssetTagResponse
98{
99 uint8_t groupID; //!< Group extension identification.
100 uint8_t tagLength; //!< Total asset tag length.
101} __attribute__((packed));
102
Tom Joseph545dd232017-07-12 20:20:49 +0530103/** @struct SetAssetTagRequest
104 *
105 * DCMI payload for Set Asset Tag command request.
106 */
107struct 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 */
118struct SetAssetTagResponse
119{
120 uint8_t groupID; //!< Group extension identification.
121 uint8_t tagLength; //!< Total asset tag length.
122} __attribute__((packed));
123
Tom Josephbe5eaa12017-07-12 19:54:44 +0530124/** @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 */
132void 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 */
138std::string readAssetTag();
139
Tom Josephbe5b9892017-07-15 00:55:23 +0530140/** @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 */
144void writeAssetTag(const std::string& assetTag);
145
Tom Josephb9d86f42017-07-26 18:03:47 +0530146/** @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 */
152uint32_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 */
161bool getPcapEnabled(sdbusplus::bus::bus& bus);
162
163/** @struct GetPowerLimitRequest
164 *
165 * DCMI payload for Get Power Limit command request.
166 */
167struct 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 */
177struct 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 Joseph46fa37d2017-07-26 18:11:55 +0530188/** @brief Set the power cap value
189 *
190 * @param[in] bus - dbus connection
191 * @param[in] powerCap - power cap value
192 */
193void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap);
194
195/** @struct SetPowerLimitRequest
196 *
197 * DCMI payload for Set Power Limit command request.
198 */
199struct 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 */
215struct SetPowerLimitResponse
216{
217 uint8_t groupID; //!< Group extension identification.
218} __attribute__((packed));
219
Tom Joseph6c8d51b2017-07-26 18:18:06 +0530220/** @brief Enable or disable the power capping
221 *
222 * @param[in] bus - dbus connection
223 * @param[in] enabled - enable/disable
224 */
225void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled);
226
227/** @struct ApplyPowerLimitRequest
228 *
229 * DCMI payload for Activate/Deactivate Power Limit command request.
230 */
231struct 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 */
242struct ApplyPowerLimitResponse
243{
244 uint8_t groupID; //!< Group extension identification.
245} __attribute__((packed));
246
Vladislav Vovchenko8f7a6f62017-08-17 00:31:14 +0300247/** @struct GetMgmntCtrlIdStrRequest
248 *
249 * DCMI payload for Get Management Controller Identifier String cmd request.
250 */
251struct 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 */
262struct 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 */
273struct 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 */
285struct SetMgmntCtrlIdStrResponse
286{
287 uint8_t groupID; //!< Group extension identification.
288 uint8_t offset; //!< Last Offset Written.
289} __attribute__((packed));
290
Dhruvaraj Subhashchandrane29be412018-01-16 05:11:56 -0600291/** @enum DCMICapParameters
292 *
293 * DCMI Capability parameters
294 */
295enum 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 */
307struct 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 */
317struct 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 */
330struct 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
338using DCMICapList = std::vector<DCMICap>;
339
340/** @struct DCMICapEntry
341 *
342 * DCMI capabilities list and size for each parameter.
343 */
344struct DCMICapEntry
345{
346 uint8_t size; //!< Size of capability array in bytes.
347 DCMICapList capList; //!< List of capabilities for a parameter.
348};
349
350using DCMICaps = std::map<DCMICapParameters, DCMICapEntry>;
351
Deepak Kodihalliee717d72018-01-24 04:53:09 -0600352/** @struct GetTempReadingsRequest
353 *
354 * DCMI payload for Get Temperature Readings request
355 */
356struct 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 */
369struct 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
376namespace 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 Josephbe5eaa12017-07-12 19:54:44 +0530405} // namespace dcmi
406
407#endif