1 #ifndef __HOST_IPMI_DCMI_HANDLER_H__
2 #define __HOST_IPMI_DCMI_HANDLER_H__
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include <sdbusplus/bus.hpp>
8 
9 namespace dcmi
10 {
11 
12 enum Commands
13 {
14     // Get capability bits
15     GET_POWER_LIMIT = 0x03,
16     SET_POWER_LIMIT = 0x04,
17     APPLY_POWER_LIMIT = 0x05,
18     GET_ASSET_TAG = 0x06,
19     SET_ASSET_TAG = 0x08,
20     GET_MGMNT_CTRL_ID_STR = 0x09,
21     SET_MGMNT_CTRL_ID_STR = 0x0A,
22 };
23 
24 static constexpr auto propIntf = "org.freedesktop.DBus.Properties";
25 static constexpr auto assetTagIntf =
26         "xyz.openbmc_project.Inventory.Decorator.AssetTag";
27 static constexpr auto assetTagProp = "AssetTag";
28 static constexpr auto networkServiceName = "xyz.openbmc_project.Network";
29 static constexpr auto networkConfigObj =
30         "/xyz/openbmc_project/network/config";
31 static constexpr auto networkConfigIntf =
32         "xyz.openbmc_project.Network.SystemConfiguration";
33 static constexpr auto hostNameProp = "HostName";
34 
35 namespace assettag
36 {
37 
38     using ObjectPath = std::string;
39     using Service = std::string;
40     using Interfaces = std::vector<std::string>;
41     using ObjectTree = std::map<ObjectPath, std::map<Service, Interfaces>>;
42 
43 } //namespace assettag
44 
45 static constexpr auto groupExtId = 0xDC;
46 
47 static constexpr auto assetTagMaxOffset = 62;
48 static constexpr auto assetTagMaxSize = 63;
49 static constexpr auto maxBytes = 16;
50 static constexpr size_t maxCtrlIdStrLen = 63;
51 
52 /** @struct GetAssetTagRequest
53  *
54  *  DCMI payload for Get Asset Tag command request.
55  */
56 struct GetAssetTagRequest
57 {
58     uint8_t groupID;            //!< Group extension identification.
59     uint8_t offset;             //!< Offset to read.
60     uint8_t bytes;              //!< Number of bytes to read.
61 } __attribute__((packed));
62 
63 /** @struct GetAssetTagResponse
64  *
65  *  DCMI payload for Get Asset Tag command response.
66  */
67 struct GetAssetTagResponse
68 {
69     uint8_t groupID;            //!< Group extension identification.
70     uint8_t tagLength;          //!< Total asset tag length.
71 } __attribute__((packed));
72 
73 /** @struct SetAssetTagRequest
74  *
75  *  DCMI payload for Set Asset Tag command request.
76  */
77 struct SetAssetTagRequest
78 {
79     uint8_t groupID;            //!< Group extension identification.
80     uint8_t offset;             //!< Offset to write.
81     uint8_t bytes;              //!< Number of bytes to write.
82 } __attribute__((packed));
83 
84 /** @struct SetAssetTagResponse
85  *
86  *  DCMI payload for Set Asset Tag command response.
87  */
88 struct SetAssetTagResponse
89 {
90     uint8_t groupID;            //!< Group extension identification.
91     uint8_t tagLength;          //!< Total asset tag length.
92 } __attribute__((packed));
93 
94 /** @brief Read the object tree to fetch the object path that implemented the
95  *         Asset tag interface.
96  *
97  *  @param[in,out] objectTree - object tree
98  *
99  *  @return On success return the object tree with the object path that
100  *          implemented the AssetTag interface.
101  */
102 void readAssetTagObjectTree(dcmi::assettag::ObjectTree& objectTree);
103 
104 /** @brief Read the asset tag of the server
105  *
106  *  @return On success return the asset tag.
107  */
108 std::string readAssetTag();
109 
110 /** @brief Write the asset tag to the asset tag DBUS property
111  *
112  *  @param[in] assetTag - Asset Tag to be written to the property.
113  */
114 void writeAssetTag(const std::string& assetTag);
115 
116 /** @brief Read the current power cap value
117  *
118  *  @param[in] bus - dbus connection
119  *
120  *  @return On success return the power cap value.
121  */
122 uint32_t getPcap(sdbusplus::bus::bus& bus);
123 
124 /** @brief Check if the power capping is enabled
125  *
126  *  @param[in] bus - dbus connection
127  *
128  *  @return true if the powerCap is enabled and false if the powercap
129  *          is disabled.
130  */
131 bool getPcapEnabled(sdbusplus::bus::bus& bus);
132 
133 /** @struct GetPowerLimitRequest
134  *
135  *  DCMI payload for Get Power Limit command request.
136  */
137 struct GetPowerLimitRequest
138 {
139     uint8_t groupID;            //!< Group extension identification.
140     uint16_t reserved;          //!< Reserved
141 } __attribute__((packed));
142 
143 /** @struct GetPowerLimitResponse
144  *
145  *  DCMI payload for Get Power Limit command response.
146  */
147 struct GetPowerLimitResponse
148 {
149     uint8_t groupID;            //!< Group extension identification.
150     uint16_t reserved;          //!< Reserved.
151     uint8_t exceptionAction;    //!< Exception action.
152     uint16_t powerLimit;        //!< Power limit requested in watts.
153     uint32_t correctionTime;    //!< Correction time limit in milliseconds.
154     uint16_t reserved1;         //!< Reserved.
155     uint16_t samplingPeriod;    //!< Statistics sampling period in seconds.
156 } __attribute__((packed));
157 
158 /** @brief Set the power cap value
159  *
160  *  @param[in] bus - dbus connection
161  *  @param[in] powerCap - power cap value
162  */
163 void setPcap(sdbusplus::bus::bus& bus, const uint32_t powerCap);
164 
165 /** @struct SetPowerLimitRequest
166  *
167  *  DCMI payload for Set Power Limit command request.
168  */
169 struct SetPowerLimitRequest
170 {
171     uint8_t groupID;            //!< Group extension identification.
172     uint16_t reserved;          //!< Reserved
173     uint8_t reserved1;          //!< Reserved
174     uint8_t exceptionAction;    //!< Exception action.
175     uint16_t powerLimit;        //!< Power limit requested in watts.
176     uint32_t correctionTime;    //!< Correction time limit in milliseconds.
177     uint16_t reserved2;         //!< Reserved.
178     uint16_t samplingPeriod;    //!< Statistics sampling period in seconds.
179 } __attribute__((packed));
180 
181 /** @struct SetPowerLimitResponse
182  *
183  *  DCMI payload for Set Power Limit command response.
184  */
185 struct SetPowerLimitResponse
186 {
187     uint8_t groupID;            //!< Group extension identification.
188 } __attribute__((packed));
189 
190 /** @brief Enable or disable the power capping
191  *
192  *  @param[in] bus - dbus connection
193  *  @param[in] enabled - enable/disable
194  */
195 void setPcapEnable(sdbusplus::bus::bus& bus, bool enabled);
196 
197 /** @struct ApplyPowerLimitRequest
198  *
199  *  DCMI payload for Activate/Deactivate Power Limit command request.
200  */
201 struct ApplyPowerLimitRequest
202 {
203     uint8_t groupID;            //!< Group extension identification.
204     uint8_t powerLimitAction;   //!< Power limit activation
205     uint16_t reserved;          //!< Reserved
206 } __attribute__((packed));
207 
208 /** @struct ApplyPowerLimitResponse
209  *
210  *  DCMI payload for Acticate/Deactivate Power Limit command response.
211  */
212 struct ApplyPowerLimitResponse
213 {
214     uint8_t groupID;            //!< Group extension identification.
215 } __attribute__((packed));
216 
217 /** @struct GetMgmntCtrlIdStrRequest
218  *
219  *  DCMI payload for Get Management Controller Identifier String cmd request.
220  */
221 struct GetMgmntCtrlIdStrRequest
222 {
223     uint8_t groupID;            //!< Group extension identification.
224     uint8_t offset;             //!< Offset to read.
225     uint8_t bytes;              //!< Number of bytes to read.
226 } __attribute__((packed));
227 
228 /** @struct GetMgmntCtrlIdStrResponse
229  *
230  *  DCMI payload for Get Management Controller Identifier String cmd response.
231  */
232 struct GetMgmntCtrlIdStrResponse
233 {
234     uint8_t groupID;            //!< Group extension identification.
235     uint8_t strLen;             //!< ID string length.
236     char data[];                //!< ID string
237 } __attribute__((packed));
238 
239 /** @struct SetMgmntCtrlIdStrRequest
240  *
241  *  DCMI payload for Set Management Controller Identifier String cmd request.
242  */
243 struct SetMgmntCtrlIdStrRequest
244 {
245     uint8_t groupID;            //!< Group extension identification.
246     uint8_t offset;             //!< Offset to write.
247     uint8_t bytes;              //!< Number of bytes to read.
248     char data[];                //!< ID string
249 } __attribute__((packed));
250 
251 /** @struct GetMgmntCtrlIdStrResponse
252  *
253  *  DCMI payload for Get Management Controller Identifier String cmd response.
254  */
255 struct SetMgmntCtrlIdStrResponse
256 {
257     uint8_t groupID;            //!< Group extension identification.
258     uint8_t offset;             //!< Last Offset Written.
259 } __attribute__((packed));
260 
261 } // namespace dcmi
262 
263 #endif
264