Api.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "main.h"
  6. #include "Api.h"
  7. #include "SDRRecord.h"
  8. #include "SELRecord.h"
  9. #include "SEL.h"
  10. int InitSdrConfig(void)
  11. {
  12. printf("Init SDR Config...\r\n");
  13. g_BMCInfo.SDRConfig.SDRError = 0;
  14. g_BMCInfo.SDRConfig.UpdatingSDR = FALSE;
  15. g_BMCInfo.SDRConfig.UpdatingChannel = 0;
  16. g_BMCInfo.SDRConfig.TrackPOffset = 0;
  17. g_BMCInfo.SDRConfig.TrackRecID = 0;
  18. g_BMCInfo.SDRConfig.ReservationID = 0;
  19. g_BMCInfo.SDRConfig.IPMB_Seqnum = 0;
  20. g_BMCInfo.SDRConfig.PartAddbytes = 0;
  21. g_BMCInfo.SDRConfig.LatestRecordID = 0;
  22. g_BMCInfo.SDRConfig.NumMarkedRecords = 0;
  23. g_BMCInfo.SDRConfig.SDRRAM = (SDRRepository_T*)g_BMCInfo.pSDR;
  24. g_BMCInfo.SDRConfig.RepositoryInfo.Version = 0x51;
  25. g_BMCInfo.SDRConfig.RepositoryInfo.RecCt = ((SDRRepository_T*)g_BMCInfo.SDRConfig.SDRRAM)->NumRecords;
  26. g_BMCInfo.SDRConfig.RepositoryInfo.FreeSpace = 0xffff;
  27. g_BMCInfo.SDRConfig.RepositoryInfo.AddTimeStamp = 0;
  28. g_BMCInfo.SDRConfig.RepositoryInfo.EraseTimeStamp = 0;
  29. g_BMCInfo.SDRConfig.RepositoryInfo.OpSupport = 0x23;
  30. //TODO:
  31. g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumAllocUnits = 0;
  32. g_BMCInfo.SDRConfig.RepositoryAllocInfo.AllocUnitSize = 0;
  33. g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits = 0;
  34. g_BMCInfo.SDRConfig.RepositoryAllocInfo.LargestFreeBlock = 0;
  35. g_BMCInfo.SDRConfig.RepositoryAllocInfo.MaxRecSize = 0;
  36. return 0;
  37. }
  38. int InitSelConfig(void)
  39. {
  40. g_BMCInfo.SELConfig.SelReservationID = 0;;
  41. g_BMCInfo.SELConfig.LastEvtTS = 0;
  42. g_BMCInfo.SELConfig.PartialAddRecordID = 0;
  43. g_BMCInfo.SELConfig.PartialAddRecOffset = 0;
  44. g_BMCInfo.SELConfig.PartialAdd = 0;
  45. g_BMCInfo.SELConfig.SenMonSELFlag = 0;
  46. g_BMCInfo.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
  47. // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
  48. g_BMCInfo.SELConfig.SELOverFlow = FALSE;
  49. g_BMCInfo.SELConfig.selalmostfull = 0;
  50. // SELEventRecord_T SelPartialAddRecord;
  51. // g_BMCInfo.SELConfig.SELEventMsg [16];
  52. return 0;
  53. }
  54. int PlatformInit(void)
  55. {
  56. uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
  57. printf("Init Platform...\r\n");
  58. g_BMCInfo.SelfTestByte = 0;
  59. g_BMCInfo.SlotID = PDK_GetSlotID();
  60. g_BMCInfo.chassisID = PDK_GetChassisID();
  61. // g_BMCInfo.PrimaryIPMBBus = PRIMARY_IPMB;
  62. // g_BMCInfo.SecondaryIPMBBus = SECONDARY_IPMB;
  63. // g_BMCInfo.PrimaryIPMBAddr = PRIMARY_IPMB_ADDR;
  64. // g_BMCInfo.SecondaryIPMBAddr = SECONDARY_IPMB_ADDR;
  65. // g_BMCInfo.SendMsgSeqNum = 0;
  66. g_BMCInfo.ChassisIdentify = FALSE;
  67. //init DevGUID
  68. g_BMCInfo.DeviceGUID[0] = 0x01;
  69. g_BMCInfo.DeviceGUID[1] = 0x01;
  70. g_BMCInfo.DeviceGUID[2] = 0x01;
  71. g_BMCInfo.DeviceGUID[3] = 0x01;
  72. g_BMCInfo.DeviceGUID[4] = 0x01;
  73. g_BMCInfo.DeviceGUID[5] = 0x01;
  74. g_BMCInfo.DeviceGUID[6] = 0x01;
  75. g_BMCInfo.DeviceGUID[7] = 0x01;
  76. g_BMCInfo.DeviceGUID[8] = 0x01;
  77. g_BMCInfo.DeviceGUID[9] = 0x01;
  78. g_BMCInfo.DeviceGUID[10] = 0x01;
  79. g_BMCInfo.DeviceGUID[11] = 0x01;
  80. g_BMCInfo.DeviceGUID[12] = 0x01;
  81. g_BMCInfo.DeviceGUID[13] = 0x01;
  82. g_BMCInfo.DeviceGUID[14] = 0x01;
  83. g_BMCInfo.DeviceGUID[15] = 0x01;
  84. g_BMCInfo.FwMajorVer = FW_VERSION_MAJOR;
  85. g_BMCInfo.FwMinorVer = FW_VERSION_MINOR;
  86. // g_BMCInfo.OemFlags.BladeWorkMode = BLADE_IPMC;
  87. // g_BMCInfo.OemFlags.chassisManageFnEnable = 0;
  88. // g_BMCInfo.OemFlags.thisBladeIndex = 0;
  89. // g_BMCInfo.OemFlags.bladeStatus = 1; //0: not present, 1: normal, 2: error, others: reserved.
  90. g_BMCInfo.HealthLevel = SENSOR_STATUS_NORMAL;
  91. g_BMCInfo.SensorSharedMem.SensorTick= 0;
  92. g_BMCInfo.SenConfig.PowerOnTick = 0;
  93. g_BMCInfo.SenConfig.SysResetTick = 0;
  94. g_BMCInfo.CurTimerTick = 0;
  95. g_BMCInfo.CurTimerSecond = 0;
  96. g_BMCInfo.BootValidMinutes = 0;
  97. g_BMCInfo.pUserInfo = NULL;
  98. // memset(g_sensorHistory, 0, sizeof(g_sensorHistory));
  99. printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.chassisID, g_BMCInfo.SlotID);
  100. printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\r\n", PrimaryIPMBBusNum,
  101. g_BMCInfo.IpmiConfig.PrimaryIPMBCh, g_BMCInfo.PrimaryIPMBAddr);
  102. printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\r\n", SecondaryIPMBBusNum,
  103. g_BMCInfo.IpmiConfig.SecondaryIPMBCh, g_BMCInfo.SecondaryIPMBAddr);
  104. return 0;
  105. }
  106. const char FirstPowerOnStr[] = "First power on the bmc";
  107. int Init_IPMI_FRU_SDR_SEL(void)
  108. {
  109. int i;
  110. uint32_t sdrSize =
  111. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  112. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  113. uint8_t* pSDR = NULL;
  114. uint8_t* pSEL = NULL;
  115. g_BMCInfo.pSDR = malloc(sdrSize);
  116. if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
  117. {
  118. printf("g_BMCInfo.pSDR Malloc failed!\r\n");
  119. }
  120. g_BMCInfo.pSEL = malloc(selSize);
  121. if((g_BMCInfo.pSDR == NULL) && (selSize != 0))
  122. {
  123. printf("g_BMCInfo.pSEL Malloc failed!\r\n");
  124. }
  125. // FLASH_GetIPMI(&g_BMCInfo.IpmiConfig);
  126. // if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
  127. if(1)
  128. {
  129. //first power on
  130. printf("BMC first power on!\r\n");
  131. /************************** Init IPMI ******************************/
  132. memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
  133. g_BMCInfo.IpmiConfig.PrimaryIPMBSupport = PRIMARY_IPMB_SUPPORT;
  134. g_BMCInfo.IpmiConfig.SecondaryIPMBSupport = SECONDARY_IPMB_SUPPORT;
  135. g_BMCInfo.IpmiConfig.GrpExtnSupport = GROUP_EXTERN_SUPPORT;
  136. g_BMCInfo.IpmiConfig.ChassisTimerInterval = CHASSIS_TIMER_INTERVAL;
  137. g_BMCInfo.IpmiConfig.PrimaryIPMBCh = PRIMARY_IPMB_CHANNEL;
  138. g_BMCInfo.IpmiConfig.SecondaryIPMBCh = SECONDARY_IPMB_CHANNEL;
  139. g_BMCInfo.IpmiConfig.PowerCycleInterval = PWR_CYCLE_INTERVAL;
  140. g_BMCInfo.IpmiConfig.FanControlInterval = FAN_CONTROL_INTERVAL;
  141. g_BMCInfo.IpmiConfig.RearmSetSensorThreshold = REARM_SET_SENSOR_THRESHOLD;
  142. g_BMCInfo.IpmiConfig.SELTimeUTCOffset = 8*60;
  143. // //set default user
  144. // memset(g_BMCInfo.IpmiConfig.UserInfoTbl, 0, sizeof(UserInfo_T)*MAX_USER_NUM);
  145. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].ID = USER_ID;
  146. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserId = 1;
  147. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].MaxPasswordSize = 20;
  148. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserStatus = TRUE;
  149. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].ChannelAccess = 0x34;
  150. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].MaxPasswordSize = 20;
  151. // memcpy(g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserName, USER_NAME, sizeof(USER_NAME));
  152. // memcpy(g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserPassword, PASS_WORD, sizeof(PASS_WORD));
  153. // g_BMCInfo.IpmiConfig.CurrentNoUser = 1;
  154. //Init FRU
  155. memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
  156. /************************ Init SDR *************************************/
  157. pSDR = g_BMCInfo.pSDR;
  158. //init SDR repository header
  159. ((SDRRepository_T*)pSDR)->Signature[0] = 0x00;
  160. ((SDRRepository_T*)pSDR)->Signature[1] = 0x11;
  161. ((SDRRepository_T*)pSDR)->Signature[2] = 0x22;
  162. ((SDRRepository_T*)pSDR)->Signature[3] = 0x33;
  163. ((SDRRepository_T*)pSDR)->NumRecords = SENSOR_NUMBERS + 1;
  164. ((SDRRepository_T*)pSDR)->Size = sdrSize;
  165. ((SDRRepository_T*)pSDR)->AddTimeStamp = 0;
  166. ((SDRRepository_T*)pSDR)->EraseTimeStamp = 0;
  167. //init MgmtCtrlrDevLocator SDR
  168. pSDR += sizeof(SDRRepository_T);
  169. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid = 1;
  170. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len = sizeof(HdrMgmtCtrlrDevLocator_T);
  171. memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
  172. //init FullSensorRec SDR
  173. pSDR += sizeof(HdrMgmtCtrlrDevLocator_T);
  174. for(i=0;i<SENSOR_NUMBERS;i++)
  175. {
  176. ((HdrFullSensorRec_T*)pSDR)->Valid = 1;
  177. ((HdrFullSensorRec_T*)pSDR)->Len = sizeof(HdrFullSensorRec_T);
  178. memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
  179. pSDR += sizeof(HdrFullSensorRec_T);
  180. }
  181. /******************************* Init SEL *************************************/
  182. pSEL = g_BMCInfo.pSEL;
  183. ((SELRepository_T*)pSEL)->Signature[0] = 0x00;
  184. ((SELRepository_T*)pSEL)->Signature[1] = 0x11;
  185. ((SELRepository_T*)pSEL)->Signature[2] = 0x22;
  186. ((SELRepository_T*)pSEL)->Signature[3] = 0x33;
  187. ((SELRepository_T*)pSEL)->NumRecords = 0;
  188. ((SELRepository_T*)pSEL)->Padding = 0;
  189. ((SELRepository_T*)pSEL)->AddTimeStamp = 0;
  190. ((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
  191. ((SELRepository_T*)pSEL)->FirstRecID = 0;
  192. ((SELRepository_T*)pSEL)->LastRecID = 0;
  193. ((SELRepository_T*)pSEL)->SELIndex = 0;
  194. ((SELRepository_T*)pSEL)->SELRecord = (SELRec_T*)(pSEL + sizeof(SELRepository_T));
  195. UpdateFlash();
  196. }
  197. else
  198. {
  199. // //Init FRU
  200. // FLASH_GetFRU(&g_BMCInfo.FRU);
  201. // //Init SDR
  202. // FLASH_GetSDR(g_BMCInfo.pSDR, sdrSize);
  203. // //Init SEL
  204. // FLASH_GetSEL(g_BMCInfo.pSEL, selSize);
  205. }
  206. return 0;
  207. }
  208. int UpdateFlash(void)
  209. {
  210. //TODO:
  211. return 0;
  212. }
  213. int SetSysTime(uint32_t *timeSecond)
  214. {
  215. g_BMCInfo.SELTimeSecond = *timeSecond;
  216. return 0;
  217. }
  218. int GetSysTime(void)
  219. {
  220. return g_BMCInfo.SELTimeSecond;
  221. }
  222. int PostEventMessage (uint8_t *EventMsg,uint8_t size)
  223. {
  224. uint8_t SelReq [sizeof(SELEventRecord_T)];
  225. uint8_t SelRes [sizeof(AddSELRes_T)];
  226. SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
  227. SelRecord->hdr.Type = 0x02;
  228. SelRecord->hdr.TimeStamp = GetSysTime ();
  229. memcpy (SelRecord->GenID, EventMsg, size);
  230. LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
  231. return 0;
  232. }
  233. uint8_t PDK_GetSlotID(void)
  234. {
  235. ;
  236. }
  237. uint8_t PDK_GetChassisID(void)
  238. {
  239. ;
  240. }
  241. int PDK_PowerOffChassis(void)
  242. {
  243. ;
  244. }
  245. int PDK_PowerOnChassis(void)
  246. {
  247. ;
  248. }
  249. int PDK_SoftOffChassis(void)
  250. {
  251. ;
  252. }
  253. int PDK_PowerCycleChassis(void)
  254. {
  255. ;
  256. }
  257. int PDK_ResetChassis(void)
  258. {
  259. ;
  260. }
  261. int PDK_DiagInterruptChassis(void)
  262. {
  263. ;
  264. }
  265. int PDK_FanControl(void)
  266. {
  267. ;
  268. }