Api.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. #include "MsgHndlr.h"
  11. int InitSdrConfig(void)
  12. {
  13. printf("Init SDR Config...\r\n");
  14. g_BMCInfo.SDRConfig.SDRError = 0;
  15. g_BMCInfo.SDRConfig.UpdatingSDR = FALSE;
  16. g_BMCInfo.SDRConfig.UpdatingChannel = 0;
  17. g_BMCInfo.SDRConfig.TrackPOffset = 0;
  18. g_BMCInfo.SDRConfig.TrackRecID = 0;
  19. g_BMCInfo.SDRConfig.ReservationID = 0;
  20. g_BMCInfo.SDRConfig.IPMB_Seqnum = 0;
  21. g_BMCInfo.SDRConfig.PartAddbytes = 0;
  22. g_BMCInfo.SDRConfig.LatestRecordID = 0;
  23. g_BMCInfo.SDRConfig.NumMarkedRecords = 0;
  24. g_BMCInfo.SDRConfig.SDRRAM = (SDRRepository_T*)g_BMCInfo.pSDR;
  25. g_BMCInfo.SDRConfig.RepositoryInfo.Version = 0x51;
  26. g_BMCInfo.SDRConfig.RepositoryInfo.RecCt = ((SDRRepository_T*)g_BMCInfo.SDRConfig.SDRRAM)->NumRecords;
  27. g_BMCInfo.SDRConfig.RepositoryInfo.FreeSpace = 0xffff;
  28. g_BMCInfo.SDRConfig.RepositoryInfo.AddTimeStamp = 0;
  29. g_BMCInfo.SDRConfig.RepositoryInfo.EraseTimeStamp = 0;
  30. g_BMCInfo.SDRConfig.RepositoryInfo.OpSupport = 0x23;
  31. //TODO:
  32. g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumAllocUnits = 0;
  33. g_BMCInfo.SDRConfig.RepositoryAllocInfo.AllocUnitSize = 0;
  34. g_BMCInfo.SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits = 0;
  35. g_BMCInfo.SDRConfig.RepositoryAllocInfo.LargestFreeBlock = 0;
  36. g_BMCInfo.SDRConfig.RepositoryAllocInfo.MaxRecSize = 0;
  37. return 0;
  38. }
  39. int InitSelConfig(void)
  40. {
  41. printf("InitSelConfig...\n");
  42. g_BMCInfo.SELConfig.SelReservationID = 0;;
  43. g_BMCInfo.SELConfig.LastEvtTS = 0;
  44. g_BMCInfo.SELConfig.PartialAddRecordID = 0;
  45. g_BMCInfo.SELConfig.PartialAddRecOffset = 0;
  46. g_BMCInfo.SELConfig.PartialAdd = 0;
  47. g_BMCInfo.SELConfig.SenMonSELFlag = 0;
  48. g_BMCInfo.SELConfig.MaxSELRecord = MAX_SEL_RECORD;
  49. // g_BMCInfo.SELConfig.RsrvIDCancelled = FALSE;
  50. g_BMCInfo.SELConfig.SELOverFlow = FALSE;
  51. g_BMCInfo.SELConfig.selalmostfull = 0;
  52. // SELEventRecord_T SelPartialAddRecord;
  53. // g_BMCInfo.SELConfig.SELEventMsg [16];
  54. return 0;
  55. }
  56. int PlatformInit(void)
  57. {
  58. uint8_t PrimaryIPMBBusNum, SecondaryIPMBBusNum;
  59. printf("Init Platform...\r\n");
  60. // //hardware init
  61. // GPIO_InitTypeDef GPIO_InitStruct;
  62. // GPIO_InitStruct.Pin = GA0_PIN | GA1_PIN | GA2_PIN | GA3_PIN | GA4_PIN | RACKID2_PIN;
  63. // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  64. // GPIO_InitStruct.Pull = GPIO_NOPULL;
  65. // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  66. // stm32_gpio_init(GPIOH, &GPIO_InitStruct);
  67. // GPIO_InitStruct.Pin = GAP_PIN | RACKID1_PIN | RACKID3_PIN | RACKID4_PIN | RACKID5_PIN;
  68. // stm32_gpio_init(GPIOI, &GPIO_InitStruct);
  69. g_BMCInfo.SelfTestByte = 0;
  70. g_BMCInfo.SlotID = PDK_GetSlotID();
  71. g_BMCInfo.ChassisID = PDK_GetChassisID();
  72. g_BMCInfo.ChassisIdentify = FALSE;
  73. //init DevGUID
  74. g_BMCInfo.DeviceGUID[0] = 0x01;
  75. g_BMCInfo.DeviceGUID[1] = 0x01;
  76. g_BMCInfo.DeviceGUID[2] = 0x01;
  77. g_BMCInfo.DeviceGUID[3] = 0x01;
  78. g_BMCInfo.DeviceGUID[4] = 0x01;
  79. g_BMCInfo.DeviceGUID[5] = 0x01;
  80. g_BMCInfo.DeviceGUID[6] = 0x01;
  81. g_BMCInfo.DeviceGUID[7] = 0x01;
  82. g_BMCInfo.DeviceGUID[8] = 0x01;
  83. g_BMCInfo.DeviceGUID[9] = 0x01;
  84. g_BMCInfo.DeviceGUID[10] = 0x01;
  85. g_BMCInfo.DeviceGUID[11] = 0x01;
  86. g_BMCInfo.DeviceGUID[12] = 0x01;
  87. g_BMCInfo.DeviceGUID[13] = 0x01;
  88. g_BMCInfo.DeviceGUID[14] = 0x01;
  89. g_BMCInfo.DeviceGUID[15] = 0x01;
  90. g_BMCInfo.FwMajorVer = FW_VERSION_MAJOR;
  91. g_BMCInfo.FwMinorVer = FW_VERSION_MINOR;
  92. g_BMCInfo.SendMsgSeqNum = 0;
  93. // g_BMCInfo.OemFlags.BladeWorkMode = BLADE_IPMC;
  94. // g_BMCInfo.OemFlags.chassisManageFnEnable = 0;
  95. // g_BMCInfo.OemFlags.thisBladeIndex = 0;
  96. // g_BMCInfo.OemFlags.bladeStatus = 1; //0: not present, 1: normal, 2: error, others: reserved.
  97. g_BMCInfo.HealthLevel = SENSOR_STATUS_NORMAL;
  98. g_BMCInfo.SensorSharedMem.SensorTick= 0;
  99. g_BMCInfo.SenConfig.PowerOnTick = 0;
  100. g_BMCInfo.SenConfig.SysResetTick = 0;
  101. g_BMCInfo.CurTimerTick = 0;
  102. g_BMCInfo.CurTimerSecond = 0;
  103. g_BMCInfo.BootValidMinutes = 0;
  104. g_BMCInfo.pUserInfo = NULL;
  105. return 0;
  106. }
  107. int InitTimerTaskTbl(void)
  108. {
  109. printf("InitTimerTaskTbl...\n");
  110. g_BMCInfo.TimerTaskTblSize = 9;
  111. memcpy(g_BMCInfo.TimerTaskTbl, m_TimerTaskTbl,sizeof(m_TimerTaskTbl));
  112. }
  113. int Init_SessionTbl(void)
  114. {
  115. printf("Init_SessionTbl...\n");
  116. g_BMCInfo.IpmiConfig.MaxSession = 10;
  117. g_BMCInfo.IpmiConfig.SessionTimeOut = 10; //10s
  118. g_BMCInfo.IpmiConfig.SendMsgTimeout = 10; //10s
  119. /*Allocating Memory to hold session Table informations */
  120. g_BMCInfo.SessionTblInfo.SessionTbl = (SessionInfo_T *) malloc(sizeof(SessionInfo_T)*( g_BMCInfo.IpmiConfig.MaxSession + 1));
  121. if(g_BMCInfo.SessionTblInfo.SessionTbl == NULL)
  122. {
  123. printf("Error in allocating memory for SessionTbl \n");
  124. return 1;
  125. }
  126. /*Initialize the Session Table memory */
  127. memset(g_BMCInfo.SessionTblInfo.SessionTbl,0,sizeof(SessionInfo_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  128. /*Allocating Memory to hold UDS session Table informations */
  129. g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl = (UDSSessionTbl_T *) malloc(sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  130. if(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl == NULL)
  131. {
  132. printf("Error in allocating memory for SessionTbl \n");
  133. return 1;
  134. }
  135. /*Initialize the UDS Session Table memory */
  136. memset(g_BMCInfo.UDSSessionTblInfo.UDSSessionTbl,0,sizeof(UDSSessionTbl_T)*(g_BMCInfo.IpmiConfig.MaxSession + 1));
  137. }
  138. const char FirstPowerOnStr[] = "First power on the bmc";
  139. int Init_IPMI_FRU_SDR_SEL(void)
  140. {
  141. int i;
  142. uint32_t sdrSize =
  143. sizeof(SDRRepository_T) + sizeof(HdrMgmtCtrlrDevLocator_T) + sizeof(HdrFullSensorRec_T)*SENSOR_NUMBERS;
  144. uint32_t selSize = sizeof(SELRepository_T) + sizeof(SELRec_T)*MAX_SEL_RECORD ;
  145. uint8_t* pSDR = NULL;
  146. uint8_t* pSEL = NULL;
  147. g_BMCInfo.pSDR = malloc(sdrSize);
  148. if((g_BMCInfo.pSDR == NULL) && (sdrSize != 0))
  149. {
  150. printf("g_BMCInfo.pSDR Malloc failed!\r\n");
  151. }
  152. g_BMCInfo.pSEL = malloc(selSize);
  153. if((g_BMCInfo.pSEL == NULL) && (selSize != 0))
  154. {
  155. printf("g_BMCInfo.pSEL Malloc failed!\r\n");
  156. }
  157. // FLASH_GetIPMI(&g_BMCInfo.IpmiConfig);
  158. // if(strncmp(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr)) != 0)
  159. if(1)
  160. {
  161. //first power on
  162. printf("BMC first power on!\r\n");
  163. /************************** Init IPMI ******************************/
  164. memcpy(g_BMCInfo.IpmiConfig.FirstPowerOnStr, FirstPowerOnStr, sizeof(FirstPowerOnStr));
  165. g_BMCInfo.IpmiConfig.SerialIfcSupport = SERIAL_IFC_SUPPORT;
  166. g_BMCInfo.IpmiConfig.SerialTerminalSupport = SERIAL_TERMINAL_SUPPORT;
  167. g_BMCInfo.IpmiConfig.LANIfcSupport = LAN_IFC_SUPPORT;
  168. g_BMCInfo.IpmiConfig.SYSIfcSupport = SYS_IFC_SUPPORT;
  169. g_BMCInfo.IpmiConfig.GrpExtnSupport = GROUP_EXTERN_SUPPORT;
  170. g_BMCInfo.IpmiConfig.UDSIfcSupport = UDS_IFC_SUPPORT;
  171. g_BMCInfo.IpmiConfig.ChassisTimerInterval = CHASSIS_TIMER_INTERVAL;
  172. g_BMCInfo.IpmiConfig.PowerCycleInterval = PWR_CYCLE_INTERVAL;
  173. g_BMCInfo.IpmiConfig.FanControlInterval = FAN_CONTROL_INTERVAL;
  174. g_BMCInfo.IpmiConfig.RearmSetSensorThreshold = REARM_SET_SENSOR_THRESHOLD;
  175. g_BMCInfo.IpmiConfig.SELTimeUTCOffset = 8*60;
  176. //IPMB
  177. g_BMCInfo.IpmiConfig.PrimaryIPMBSupport = PRIMARY_IPMB_SUPPORT;
  178. g_BMCInfo.IpmiConfig.SecondaryIPMBSupport = SECONDARY_IPMB_SUPPORT;
  179. g_BMCInfo.IpmiConfig.PrimaryIPMBBus = PRIMARY_IPMB_BUS;
  180. g_BMCInfo.IpmiConfig.SecondaryIPMBBus = SECONDARY_IPMB_BUS;
  181. g_BMCInfo.IpmiConfig.PrimaryIPMBAddr = PRIMARY_IPMB_ADDR;
  182. g_BMCInfo.IpmiConfig.SecondaryIPMBAddr = SECONDARY_IPMB_ADDR;
  183. // //set default user
  184. // memset(g_BMCInfo.IpmiConfig.UserInfoTbl, 0, sizeof(UserInfo_T)*MAX_USER_NUM);
  185. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].ID = USER_ID;
  186. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserId = 1;
  187. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].MaxPasswordSize = 20;
  188. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserStatus = TRUE;
  189. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].ChannelAccess = 0x34;
  190. // g_BMCInfo.IpmiConfig.UserInfoTbl[0].MaxPasswordSize = 20;
  191. // memcpy(g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserName, USER_NAME, sizeof(USER_NAME));
  192. // memcpy(g_BMCInfo.IpmiConfig.UserInfoTbl[0].UserPassword, PASS_WORD, sizeof(PASS_WORD));
  193. // g_BMCInfo.IpmiConfig.CurrentNoUser = 1;
  194. //Init FRU
  195. memcpy(&g_BMCInfo.FRU, &Default_FRUData, sizeof(OemFRUData_T));
  196. /************************ Init SDR *************************************/
  197. pSDR = g_BMCInfo.pSDR;
  198. //init SDR repository header
  199. ((SDRRepository_T*)pSDR)->Signature[0] = 0x00;
  200. ((SDRRepository_T*)pSDR)->Signature[1] = 0x11;
  201. ((SDRRepository_T*)pSDR)->Signature[2] = 0x22;
  202. ((SDRRepository_T*)pSDR)->Signature[3] = 0x33;
  203. ((SDRRepository_T*)pSDR)->NumRecords = SENSOR_NUMBERS + 1;
  204. ((SDRRepository_T*)pSDR)->Size = sdrSize;
  205. ((SDRRepository_T*)pSDR)->AddTimeStamp = 0;
  206. ((SDRRepository_T*)pSDR)->EraseTimeStamp = 0;
  207. //init MgmtCtrlrDevLocator SDR
  208. pSDR += sizeof(SDRRepository_T);
  209. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Valid = 1;
  210. ((HdrMgmtCtrlrDevLocator_T*)pSDR)->Len = sizeof(HdrMgmtCtrlrDevLocator_T);
  211. memcpy(&(((HdrMgmtCtrlrDevLocator_T*)pSDR)->MgmtCtrlrDevLocator), &bmc_sdr, sizeof(MgmtCtrlrDevLocator_T));
  212. //init FullSensorRec SDR
  213. pSDR += sizeof(HdrMgmtCtrlrDevLocator_T);
  214. for(i=0;i<SENSOR_NUMBERS;i++)
  215. {
  216. ((HdrFullSensorRec_T*)pSDR)->Valid = 1;
  217. ((HdrFullSensorRec_T*)pSDR)->Len = sizeof(HdrFullSensorRec_T);
  218. memcpy(&(((HdrFullSensorRec_T*)pSDR)->FullSensorRec), &full_sdr_tbl[i], sizeof(FullSensorRec_T));
  219. pSDR += sizeof(HdrFullSensorRec_T);
  220. }
  221. /******************************* Init SEL *************************************/
  222. pSEL = g_BMCInfo.pSEL;
  223. ((SELRepository_T*)pSEL)->Signature[0] = 0x00;
  224. ((SELRepository_T*)pSEL)->Signature[1] = 0x11;
  225. ((SELRepository_T*)pSEL)->Signature[2] = 0x22;
  226. ((SELRepository_T*)pSEL)->Signature[3] = 0x33;
  227. ((SELRepository_T*)pSEL)->NumRecords = 0;
  228. ((SELRepository_T*)pSEL)->Padding = 0;
  229. ((SELRepository_T*)pSEL)->AddTimeStamp = 0;
  230. ((SELRepository_T*)pSEL)->EraseTimeStamp = 0;
  231. ((SELRepository_T*)pSEL)->FirstRecID = 0;
  232. ((SELRepository_T*)pSEL)->LastRecID = 0;
  233. ((SELRepository_T*)pSEL)->SELIndex = 0;
  234. ((SELRepository_T*)pSEL)->SELRecord = (SELRec_T*)(pSEL + sizeof(SELRepository_T));
  235. UpdateFlash();
  236. }
  237. else
  238. {
  239. // //Init FRU
  240. // FLASH_GetFRU(&g_BMCInfo.FRU);
  241. // //Init SDR
  242. // FLASH_GetSDR(g_BMCInfo.pSDR, sdrSize);
  243. // //Init SEL
  244. // FLASH_GetSEL(g_BMCInfo.pSEL, selSize);
  245. }
  246. return 0;
  247. }
  248. int UpdateFlash(void)
  249. {
  250. //TODO:
  251. return 0;
  252. }
  253. int SetSysTime(uint32_t *timeSecond)
  254. {
  255. g_BMCInfo.SELTimeSecond = *timeSecond;
  256. return 0;
  257. }
  258. int GetSysTime(void)
  259. {
  260. return g_BMCInfo.SELTimeSecond;
  261. }
  262. int PostEventMessage (uint8_t *EventMsg,uint8_t size)
  263. {
  264. uint8_t SelReq [sizeof(SELEventRecord_T)];
  265. uint8_t SelRes [sizeof(AddSELRes_T)];
  266. SELEventRecord_T* SelRecord = ( SELEventRecord_T*) SelReq;
  267. SelRecord->hdr.Type = 0x02;
  268. SelRecord->hdr.TimeStamp = GetSysTime ();
  269. memcpy (SelRecord->GenID, EventMsg, size);
  270. LockedAddSELEntry(SelReq, sizeof (SELEventRecord_T), SelRes);
  271. return 0;
  272. }
  273. uint8_t PDK_GetSlotID(void)
  274. {
  275. uint8_t SlotID = 0;
  276. uint8_t check = 0;
  277. if(stm32_gpio_read(GA0_PORT, GA0_PIN) == GPIO_PIN_RESET)
  278. SlotID |= 0x01;
  279. if(stm32_gpio_read(GA1_PORT, GA1_PIN) == GPIO_PIN_RESET)
  280. SlotID |= 0x02;
  281. if(stm32_gpio_read(GA2_PORT, GA2_PIN) == GPIO_PIN_RESET)
  282. SlotID |= 0x04;
  283. if(stm32_gpio_read(GA3_PORT, GA3_PIN) == GPIO_PIN_RESET)
  284. SlotID |= 0x08;
  285. if(stm32_gpio_read(GA4_PORT, GA4_PIN) == GPIO_PIN_RESET)
  286. SlotID |= 0x10;
  287. if(stm32_gpio_read(GAP_PORT, GAP_PIN) == GPIO_PIN_RESET)
  288. SlotID |= 0x20;
  289. int i;
  290. for(i=0;i<6;i++)
  291. check ^= (SlotID>>i)&0x01;
  292. if(check == 0)
  293. printf("Slot ID check error! GAP = %#x, GA[4:0] = %#x.\n", (SlotID>>5), (SlotID&0x1f));
  294. return SlotID&0x1f;
  295. }
  296. uint8_t PDK_GetChassisID(void)
  297. {
  298. uint8_t ChassisID = 0;
  299. if(stm32_gpio_read(RACKID0_PORT, RACKID0_PIN) == GPIO_PIN_SET)
  300. ChassisID |= 0x01;
  301. if(stm32_gpio_read(RACKID1_PORT, RACKID1_PIN) == GPIO_PIN_SET)
  302. ChassisID |= 0x02;
  303. if(stm32_gpio_read(RACKID2_PORT, RACKID2_PIN) == GPIO_PIN_SET)
  304. ChassisID |= 0x04;
  305. if(stm32_gpio_read(RACKID3_PORT, RACKID3_PIN) == GPIO_PIN_SET)
  306. ChassisID |= 0x08;
  307. if(stm32_gpio_read(RACKID4_PORT, RACKID4_PIN) == GPIO_PIN_SET)
  308. ChassisID |= 0x10;
  309. if(stm32_gpio_read(RACKID5_PORT, RACKID5_PIN) == GPIO_PIN_SET)
  310. ChassisID |= 0x20;
  311. return ChassisID;
  312. }
  313. int PDK_PowerOffChassis(void)
  314. {
  315. printf("power off chassis\n");
  316. }
  317. int PDK_PowerOnChassis(void)
  318. {
  319. printf("power on chassis\n");
  320. }
  321. int PDK_SoftOffChassis(void)
  322. {
  323. printf("soft off chassis\n");;
  324. }
  325. int PDK_PowerCycleChassis(void)
  326. {
  327. printf("power cycle chassis\n");;
  328. }
  329. int PDK_ResetChassis(void)
  330. {
  331. printf("power reset chassis\n");;
  332. }
  333. int PDK_DiagInterruptChassis(void)
  334. {
  335. printf("power diag chassis\n");;
  336. }
  337. int PDK_FanControl(void)
  338. {
  339. ;
  340. }