1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #pragma once
18 
19 #include <ipmid/api-types.hpp>
20 #include <user_channel/user_layer.hpp>
21 namespace ipmi
22 {
23 namespace intel
24 {
25 
26 static constexpr NetFn netFnGeneral = netFnOemOne;
27 static constexpr NetFn netFnPlatform = netFnOemTwo;
28 static constexpr NetFn netFnApp = netFnOemEight;
29 
30 namespace general
31 {
32 static constexpr Cmd cmdRestoreConfiguration = 0x02;
33 static constexpr Cmd cmdGetSmSignal = 0x14;
34 static constexpr Cmd cmdSetSmSignal = 0x15;
35 static constexpr Cmd cmdSetBIOSID = 0x26;
36 static constexpr Cmd cmdGetOEMDeviceInfo = 0x27;
37 static constexpr Cmd cmdSetColdRedundancyConfig = 0x2d;
38 static constexpr Cmd cmdGetColdRedundancyConfig = 0x2e;
39 static constexpr Cmd cmdGetAICSlotFRUIDSlotPosRecords = 0x31;
40 static constexpr Cmd cmdGetMultiNodeRole = 0x33;
41 static constexpr Cmd cmdGetMultiNodeId = 0x36;
42 static constexpr Cmd cmdSetSystemGUID = 0x41;
43 static constexpr Cmd cmdDisableBMCSystemReset = 0x42;
44 static constexpr Cmd cmdGetBMCResetDisables = 0x43;
45 static constexpr Cmd cmdSendEmbeddedFWUpdStatus = 0x44;
46 static constexpr Cmd cmdSlotI2CMasterWriteRead = 0x52;
47 static constexpr Cmd cmdSetPowerRestoreDelay = 0x54;
48 static constexpr Cmd cmdGetPowerRestoreDelay = 0x55;
49 static constexpr Cmd cmdSetFaultIndication = 0x57;
50 static constexpr Cmd cmdSetOEMUser2Activation = 0x5A;
51 static constexpr Cmd cmdSetSpecialUserPassword = 0x5F;
52 static constexpr Cmd cmdSetShutdownPolicy = 0x60;
53 static constexpr Cmd cmdGetShutdownPolicy = 0x62;
54 static constexpr Cmd cmdGetMultiNodePresence = 0x63;
55 static constexpr Cmd cmdSetFanConfig = 0x89;
56 static constexpr Cmd cmdGetFanConfig = 0x8a;
57 static constexpr Cmd cmdSetFanSpeedOffset = 0x8c;
58 static constexpr Cmd cmdGetFanSpeedOffset = 0x8d;
59 static constexpr Cmd cmdSetDimmOffset = 0x8e;
60 static constexpr Cmd cmdGetDimmOffset = 0x8f;
61 static constexpr Cmd cmdSetFscParameter = 0x90;
62 static constexpr Cmd cmdGetFscParameter = 0x91;
63 static constexpr Cmd cmdGetChassisIdentifier = 0x92;
64 static constexpr Cmd cmdReadBaseBoardProductId = 0x93;
65 static constexpr Cmd cmdGetProcessorErrConfig = 0x9A;
66 static constexpr Cmd cmdSetProcessorErrConfig = 0x9B;
67 static constexpr Cmd cmdSetManufacturingData = 0xA1;
68 static constexpr Cmd cmdGetManufacturingData = 0xA2;
69 static constexpr Cmd cmdGetLEDStatus = 0xB0;
70 static constexpr Cmd cmdControlBmcServices = 0xB1;
71 static constexpr Cmd cmdGetBmcServiceStatus = 0xB2;
72 static constexpr Cmd cmdGetSecurityMode = 0xB3;
73 static constexpr Cmd cmdSetSecurityMode = 0xB4;
74 static constexpr Cmd cmdMtmKeepAlive = 0xB5;
75 static constexpr Cmd cmdGetNmiStatus = 0xE5;
76 static constexpr Cmd cmdSetEfiBootOptions = 0xEA;
77 static constexpr Cmd cmdGetEfiBootOptions = 0xEB;
78 static constexpr Cmd cmdSetNmiStatus = 0xED;
79 static constexpr Cmd cmdGetPSUVersion = 0xEF;
80 } // namespace general
81 
82 namespace platform
83 {
84 static constexpr Cmd cmdCfgHostSerialPortSpeed = 0x90;
85 static constexpr Cmd cmdClearCMOS = 0x91;
86 } // namespace platform
87 
88 namespace app
89 {
90 static constexpr Cmd cmdMdrStatus = 0x20;
91 static constexpr Cmd cmdMdrComplete = 0x21;
92 static constexpr Cmd cmdMdrEvent = 0x22;
93 static constexpr Cmd cmdMdrRead = 0x23;
94 static constexpr Cmd cmdMdrWrite = 0x24;
95 static constexpr Cmd cmdMdrLock = 0x25;
96 static constexpr Cmd cmdMdrIIAgentStatus = 0x30;
97 static constexpr Cmd cmdMdrIIGetDir = 0x31;
98 static constexpr Cmd cmdMdrIIGetDataInfo = 0x32;
99 static constexpr Cmd cmdMdrIILockData = 0x33;
100 static constexpr Cmd cmdMdrIIUnlockData = 0X34;
101 static constexpr Cmd cmdMdrIIGetDataBlock = 0x35;
102 static constexpr Cmd cmdMdrIISendDir = 0x38;
103 static constexpr Cmd cmdMdrIISendDataInfoOffer = 0x39;
104 static constexpr Cmd cmdMdrIISendDataInfo = 0x3a;
105 static constexpr Cmd cmdMdrIIDataStart = 0x3b;
106 static constexpr Cmd cmdMdrIIDataDone = 0x3c;
107 static constexpr Cmd cmdMdrIISendDataBlock = 0x3d;
108 } // namespace app
109 
110 } // namespace intel
111 
112 } // namespace ipmi
113 
114 // FIXME: put these in the cpp files that use them
115 enum class IPMIIntelOEMReturnCodes
116 {
117     ipmiCCPayloadActive = 0x80,
118     ipmiCCInvalidPCIESlotID = 0x80,
119     ipmiCCParameterNotSupported = 0x80,
120     ipmiCCPayloadAlreadyDeactivated = 0x80,
121     ipmiCCSetInProcess = 0x81,
122     ipmiCCPayloadDisable = 0x81,
123     ipmiCCLostArbitration = 0x81,
124     ipmiCCInvalidCablePortIndex = 0x81,
125     ipmiCCHealthStatusNotAvailable = 0x81,
126     ipmiCCBusError = 0x82,
127     ipmiCCReadOnly = 0x82,
128     ipmiCCWriteOnly = 0x82,
129     ipmiCCNoCablePresent = 0x82,
130     ipmiCCDataCollectionInProgress = 0x82,
131     ipmiCCPayloadActivationLimitReached = 0x82,
132     ipmiCCNACKOnWrite = 0x83,
133     ipmiCCDataCollectionFailed = 0x83,
134     ipmiCCCanNotActivateWithEncrption = 0x83,
135     ipmiCCCanNotActivateWithoutEncryption = 0x84,
136     ipmiCCInvalidChecksum = 0x85,
137     ipmiCCNoCabledPCIEPortsAvailable = 0xC2,
138 
139 };
140 
141 enum class IPMIReturnCodeExt
142 {
143     ipmiCCInvalidLUN = 0xC2,
144     ipmiCCTimeout = 0xC3,
145     ipmiCCStorageLeak = 0xC4,
146     ipmiCCRequestDataTruncated = 0xC6,
147     ipmiCCRequestDataFieldLengthLimitExceeded = 0xC8,
148     ipmiCCCanNotReturnNumberOfRequestedDataBytes = 0xCA,
149     ipmiCCRequestSensorDataRecordNotFound = 0xCB,
150     ipmiCCDestinationUnavailable = 0xD3,
151     ipmiCCParamterNotSupportInPresentState = 0xD5,
152 };
153 
154 static constexpr const uint8_t maxBIOSIDLength = 0xFF;
155 static constexpr const uint8_t maxCPUNum = 4;
156 static constexpr const char* biosObjPath = "/xyz/openbmc_project/bios";
157 static constexpr const char* biosIntf =
158     "xyz.openbmc_project.Inventory.Item.Bios";
159 static constexpr const char* biosProp = "BiosId";
160 
161 static constexpr const char* powerRestoreDelayObjPath =
162     "/xyz/openbmc_project/control/power_restore_delay";
163 static constexpr const char* powerRestoreDelayIntf =
164     "xyz.openbmc_project.Control.Power.RestoreDelay";
165 static constexpr const char* powerRestoreDelayProp = "PowerRestoreDelay";
166 static constexpr const char* processorErrConfigObjPath =
167     "/xyz/openbmc_project/control/processor_error_config";
168 static constexpr const char* processorErrConfigIntf =
169     "xyz.openbmc_project.Control.Processor.ErrConfig";
170 static constexpr const char* bmcResetDisablesPath =
171     "/xyz/openbmc_project/control/bmc_reset_disables";
172 static constexpr const char* bmcResetDisablesIntf =
173     "xyz.openbmc_project.Control.ResetDisables";
174 
175 static constexpr const char* postCodesObjPath =
176     "/xyz/openbmc_project/State/Boot/PostCode";
177 static constexpr const char* postCodesIntf =
178     "xyz.openbmc_project.State.Boot.PostCode";
179 
180 static constexpr const char* identifyLEDObjPath =
181     "/xyz/openbmc_project/led/physical/identify";
182 static constexpr const char* ledIntf = "xyz.openbmc_project.Led.Physical";
183 static constexpr const char* statusAmberObjPath =
184     "/xyz/openbmc_project/led/physical/status_amber";
185 static constexpr const char* statusGreenObjPath =
186     "/xyz/openbmc_project/led/physical/status_green";
187 
188 static constexpr const uint8_t noShutdownOnOCOT = 0;
189 static constexpr const uint8_t shutdownOnOCOT = 1;
190 static constexpr const uint8_t noShutdownPolicySupported = 0;
191 static constexpr const uint8_t shutdownPolicySupported = 1;
192 static constexpr const char* oemShutdownPolicyIntf =
193     "com.intel.Control.OCOTShutdownPolicy";
194 static constexpr const char* oemShutdownPolicyObjPath =
195     "/com/intel/control/ocotshutdown_policy_config";
196 static constexpr const char* oemShutdownPolicyObjPathProp = "OCOTPolicy";
197 
198 static constexpr const char* fwGetEnvCmd = "/sbin/fw_printenv";
199 static constexpr const char* fwSetEnvCmd = "/sbin/fw_setenv";
200 static constexpr const char* fwHostSerailCfgEnvName = "hostserialcfg";
201 
202 constexpr const char* settingsBusName = "xyz.openbmc_project.Settings";
203 
204 static constexpr const uint8_t getHostSerialCfgCmd = 0;
205 static constexpr const uint8_t setHostSerialCfgCmd = 1;
206 
207 // parameters:
208 // 0: host serial port 1 and 2 normal speed
209 // 1: host serial port 1 high spend, port 2 normal speed
210 // 2: host serial port 1 normal spend, port 2 high speed
211 // 3: host serial port 1 and 2 high speed
212 static constexpr const uint8_t HostSerialCfgParamMax = 3;
213 static constexpr uint8_t ipmiDefaultUserId = 2;
214 
215 static constexpr const uint8_t selEvtTargetMask = 0xF0;
216 static constexpr const uint8_t selEvtTargetShift = 4;
217 
218 static constexpr const uint8_t targetInstanceMask = 0x0E;
219 static constexpr const uint8_t targetInstanceShift = 1;
220 
221 enum class IPMINetfnIntelOEMAppCmd
222 {
223     mdrStatus = 0x20,
224     mdrComplete = 0x21,
225     mdrEvent = 0x22,
226     mdrRead = 0x23,
227     mdrWrite = 0x24,
228     mdrLock = 0x25,
229     mdr2AgentStatus = 0x30,
230     mdr2GetDir = 0x31,
231     mdr2GetDataInfo = 0x32,
232     mdr2LockData = 0x33,
233     mdr2UnlockData = 0x34,
234     mdr2GetDataBlock = 0x35,
235     mdr2SendDir = 0x38,
236     mdr2SendDataInfoOffer = 0x39,
237     mdr2SendDataInfo = 0x3a,
238     mdr2DataStart = 0x3b,
239     mdr2DataDone = 0x3c,
240     mdr2SendDataBlock = 0x3d,
241 };
242 
243 enum class OEMDevEntityType
244 {
245     biosId,
246     devVer,
247     sdrVer,
248 };
249 
250 enum class FWUpdateTarget : uint8_t
251 {
252     targetBMC = 0x0,
253     targetBIOS = 0x1,
254     targetME = 0x2,
255     targetOEMEWS = 0x4,
256 };
257 
258 enum class CPUStatus
259 {
260     disabled = 0x0,
261     enabled = 0x1,
262     notPresent = 0x3,
263 };
264 
265 #pragma pack(push, 1)
266 struct GUIDData
267 {
268     uint8_t node1;
269     uint8_t node2;
270     uint8_t node3;
271     uint8_t node4;
272     uint8_t node5;
273     uint8_t node6;
274     uint8_t clock1;
275     uint8_t clock2;
276     uint8_t timeHigh1;
277     uint8_t timeHigh2;
278     uint8_t timeMid1;
279     uint8_t timeMid2;
280     uint8_t timeLow1;
281     uint8_t timeLow2;
282     uint8_t timeLow3;
283     uint8_t timeLow4;
284 };
285 
286 struct DeviceInfo
287 {
288     uint8_t biosIDLength;
289     uint8_t biosId[maxBIOSIDLength];
290 };
291 
292 struct SetPowerRestoreDelayReq
293 {
294     uint8_t byteMSB;
295     uint8_t byteLSB;
296 };
297 
298 struct GetPowerRestoreDelayRes
299 {
300     uint8_t byteMSB;
301     uint8_t byteLSB;
302 };
303 
304 struct GetOemDeviceInfoReq
305 {
306     uint8_t entityType;
307     uint8_t countToRead;
308     uint8_t offset;
309 };
310 
311 struct GetOemDeviceInfoRes
312 {
313     uint8_t resDatalen;
314     uint8_t data[maxBIOSIDLength];
315 };
316 
317 struct GetOEMShutdownPolicyRes
318 {
319     uint8_t policy;
320     uint8_t policySupport;
321 };
322 
323 struct SetFanConfigReq
324 {
325     uint8_t selectedProfile;
326     uint8_t flags;
327     // other parameters from previous generation are not supported
328 };
329 struct CfgHostSerialReq
330 {
331     uint8_t command;
332     uint8_t parameter;
333 };
334 #pragma pack(pop)
335 
336 //
337 // Fault type enumeration
338 //
339 enum class RemoteFaultType
340 {
341     fan,         // 0
342     temperature, // 1
343     power,       // 2
344     driveslot,   // 3
345     software,    // 4
346     memory,      // 5
347     max = 6      // 6
348 };
349 
350 // Enumeration for remote fault states as required by the HSC
351 //
352 enum class RemoteFaultState
353 {
354     // fault indicators
355     fanLEDs,
356     cpu1DimmLeds,
357     cpu2DimmLeds,
358     cpu3DimmLeds,
359     cpu4DimmLeds,
360     maxFaultState,
361 };
362 
363 enum class DimmFaultType
364 {
365     cpu1cpu2Dimm,
366     cpu3cpu4Dimm,
367     maxFaultGroup,
368 };
369 
370 enum class setFanProfileFlags : uint8_t
371 {
372     setFanProfile = 7,
373     setPerfAcousMode = 6,
374     // reserved [5:3]
375     performAcousSelect = 2
376     // reserved [1:0]
377 };
378 
379 enum class setFscParamFlags : uint8_t
380 {
381     tcontrol = 0x1,
382     pwmOffset = 0x2,
383     maxPwm = 0x3,
384     cfm = 0x4
385 };
386 
387 enum class dimmOffsetTypes : uint8_t
388 {
389     staticCltt = 0x0,
390     dimmPower = 0x2
391 };
392 
393 // FIXME: this stuff needs to be rewritten
394 enum IPMI_INTEL_OEM_RETURN_CODES
395 {
396     IPMI_CC_OEM_PAYLOAD_ACTIVE = 0x80,
397     IPMI_CC_OEM_INVALID_PCIE_SLOTID = 0x80,
398     IPMI_CC_OEM_PARAMETER_NOT_SUPPORTED = 0x80,
399     IPMI_CC_OEM_PAYLOAD_ALREADY_DEACTIVATED = 0x80,
400     IPMI_CC_OEM_SET_IN_PROCESS = 0x81,
401     IPMI_CC_OEM_PAYLOAD_DISABLE = 0x81,
402     IPMI_CC_OEM_LOST_ARBITRATION = 0x81,
403     IPMI_CC_OEM_INVALID_CABLE_PORT_INDEX = 0x81,
404     IPMI_CC_OEM_HEALTH_STATUS_NOT_AVAILABLE = 0x81,
405     IPMI_CC_OEM_BUS_ERROR = 0x82,
406     IPMI_CC_OEM_READ_ONLY = 0x82,
407     IPMI_CC_OEM_WRITE_ONLY = 0x82,
408     IPMI_CC_OEM_NO_CABLE_PRESENT = 0x82,
409     IPMI_CC_OEM_DATA_COLLECTION_IN_PROGRESS = 0x82,
410     IPMI_CC_OEM_PAYLOAD_ACTIVATION_LIMIT_REACH = 0x82,
411     IPMI_CC_OEM_NACK_ON_WRITE = 0x83,
412     IPMI_CC_OEM_DATA_COLLECTION_FAILED = 0x83,
413     IPMI_CC_OEM_CAN_NOT_ACTIVATE_WITH_ENCRYPTION = 0x83,
414     IPMI_CC_OEM_CAN_NOT_ACTIVATE_WITHOUT_ENCRYPTION = 0x84,
415     IPMI_CC_OEM_INVALID_CHECKSUM = 0x85,
416     IPMI_CC_OEM_NO_CABLED_PCIE_PORTS_AVAILABLE = 0xC2,
417 };
418 
419 enum IPMI_RETURN_CODE_EXT
420 {
421     IPMI_CC_INVALID_LUN = 0xC2,
422     IPMI_CC_STORGE_LEAK = 0xC4,
423     IPMI_CC_REQUEST_DATA_TRUNCATED = 0xC6,
424     IPMI_CC_REQUEST_DATA_FIELD_LENGTH_LIMIT_EXCEEDED = 0xC8,
425     IPMI_CC_CANNOT_RETURN_NUMBER_OF_REQUESTED_DATA_BYTES = 0xCA,
426     IPMI_CC_REQUEST_SENSOR_DATA_RECORD_NOT_FOUND = 0xCB,
427     IPMI_CC_DESTINATION_UNAVAILABLE = 0xD3,
428     IPMI_CC_PARAMETER_NOT_SUPPORT_IN_PRESENT_STATE = 0xD5,
429 };
430