SDR.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. /*****************************************************************
  2. *****************************************************************
  3. *** **
  4. *** (C)Copyright 2005-2006, American Megatrends Inc. **
  5. *** **
  6. *** All Rights Reserved. **
  7. *** **
  8. *** 6145-F, Northbelt Parkway, Norcross, **
  9. *** **
  10. *** Georgia - 30071, USA. Phone-(770)-246-8600. **
  11. *** **
  12. *****************************************************************
  13. ******************************************************************
  14. *
  15. * SDR.c
  16. * SDR functions.
  17. *
  18. * Author: Govind Kothandapani <govindk@ami.com>
  19. *
  20. ******************************************************************/
  21. //#include "main.h"
  22. #include "com_IPMI_SDRRecord.h"
  23. #include "SDR.h"
  24. #include "SDRRecord.h"
  25. #include <string.h>
  26. #include "Support.h"
  27. #include "SDRFunc.h"
  28. #include "main.h"
  29. /**
  30. * NVRAM Handles
  31. **/
  32. #define NVRH_USERCONFIG 0
  33. #define NVRH_CHCONFIG 0
  34. #define NVRH_SDR 0
  35. /* Reserved bit macro definitions */
  36. #define RESERVED_BITS_PARTIALADDSDR 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  37. #if SDR_DEVICE == 1
  38. #define SUPPORT_MULTI_CONTROLLER 1
  39. /*** Local Definitions ***/
  40. #define SDR_FIRST_FREE_BYTE() ((( uint8_t*)g_BMCInfo.SDRConfig.SDRRAM) + g_BMCInfo.SDRConfig.SDRRAM->Size)
  41. #define MAX_SDR_LEN 25
  42. #define MAX_RES_LEN 128
  43. #define SDR_VERSION 0x51
  44. #define CMD_RUN_INITIALIZATION_AGENT 0x2C
  45. #define MANAGEMENT_DEV_LOC_REC 0x12
  46. #define PARTIAL_ADD_SDR_SUPPORT 0x04
  47. #define RESERVE_SDR_SUPPORT 0x02
  48. #define GET_SDR_REPOSITORY_ALLOC_SUPPORT 0x01
  49. #define NON_MODAL_SUPPORT 0x20
  50. #define NO_SUPPORT 0x00
  51. #define DELETE_SDR_SUPPORT 0x08
  52. #define MAX_OEM_REC_LEN 64
  53. #define SDR_ALLOC_UNIT_SIZE 0x10
  54. #define SDR_MAX_RECORD_SIZE 0x80
  55. #define SDR_ERASE_COMPLETED 0x01
  56. #define SDR_INIT_COMPLETED 0x01
  57. #define ENABLE_SELECTED_EVENT_MSG 0x10
  58. #define DISABLE_SELECTED_EVENT_MSG 0x20
  59. #define OEM_SDR_NM_REC 0x0D
  60. /**
  61. * @brief Size of SDR Record
  62. **/
  63. #define SDR_SIZE(SDRRecHdr) (sizeof (SDRRecHdr_T) + (SDRRecHdr)->Len)
  64. /**
  65. * @brief Size the SDR Record occupies in the memory
  66. **/
  67. #define SDR_SIZE_IN_MEM(SDRRecHdr) \
  68. (((SDR_SIZE(SDRRecHdr) & 0x0f) == 0) ? SDR_SIZE(SDRRecHdr) : \
  69. (SDR_SIZE(SDRRecHdr) & 0xf0) + 0x10)
  70. /*** Prototype Declarations ***/
  71. static uint8_t PreCheckSDRUpdateModeCmd ( uint8_t* pRes);
  72. static uint16_t SDR_ReserveSDRRepository (void);
  73. static SDRRecHdr_T* GetLastSDRRec (void);
  74. //static void UpdateRepositoryInfo (void);
  75. static SDRRecHdr_T* SDR_GetSDRRec (uint16_t RecID, uint16_t ReservationID);
  76. //static void SDRInitAgent (void);
  77. //static uint8_t ValidateSDRSize (uint8_t SDRType, uint8_t Size);
  78. //const uint8_t SDRSize [][2] = {
  79. //// { SDR Type, Maximum Length },
  80. // { FULL_SDR_REC, 64 },
  81. // { COMPACT_SDR_REC, 48 },
  82. // { EVENT_ONLY_SDR_REC, 33 },
  83. // { ENTITY_ASSOCIATION_SDR_REC, 16 },
  84. // { DEV_REL_ENTITY_ASSOCIATION_SDR_REC, 32 },
  85. // { GENERIC_DEVICE_LOCATOR_SDR_REC, 32 },
  86. // { FRU_DEVICE_LOCATOR_SDR_REC, 32 },
  87. // { MGMT_CTRL_DEV_LOCATOR_SDR_REC, 32 },
  88. // { MGMT_CTRL_CONFIRMATION_SDR_REC, 32 },
  89. // { BMC_MSG_CHANNEL_INFO_REC, 16 },
  90. // };
  91. static uint16_t SDR_AddSDRRec ( SDRRecHdr_T* pSDRRecHdr);
  92. static uint16_t SDR_PartialAddSDR ( uint8_t* SDRData, uint8_t Offset, uint8_t Size,uint8_t IsLast, uint16_t ReservationID);
  93. #define CLEAR_SDR_INITIATE_ERASE 0xAA
  94. #define CLEAR_SDR_GET_STATUS 0x00
  95. static int SDR_ClearSDRRepository (uint16_t ReservationID, uint8_t InitOrStatus);
  96. //static uint16_t SDR_DeleteSDR (uint16_t ReservationID, uint16_t RecID);
  97. /*---------------------------------------
  98. * GetSDRRepositoryInfo
  99. *---------------------------------------*/
  100. int
  101. GetSDRRepositoryInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  102. {
  103. SDRRepositoryInfo_T* pSDRRepInfoRes =
  104. ( SDRRepositoryInfo_T*) pRes;
  105. memcpy (pSDRRepInfoRes, &g_BMCInfo.SDRConfig.RepositoryInfo, sizeof (SDRRepositoryInfo_T));
  106. pSDRRepInfoRes->CompletionCode = CC_NORMAL;
  107. return sizeof (SDRRepositoryInfo_T);
  108. }
  109. /*---------------------------------------
  110. * GetSDRRepositoryAllocInfo
  111. *---------------------------------------*/
  112. int
  113. GetSDRRepositoryAllocInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  114. {
  115. SDRRepositoryAllocInfo_T* pSDRRepAllocInfoRes =
  116. ( SDRRepositoryAllocInfo_T*) pRes;
  117. memcpy (pSDRRepAllocInfoRes, &g_BMCInfo.SDRConfig.RepositoryAllocInfo,
  118. sizeof (SDRRepositoryAllocInfo_T));
  119. pSDRRepAllocInfoRes->CompletionCode = CC_NORMAL;
  120. return sizeof (SDRRepositoryAllocInfo_T);
  121. }
  122. /*---------------------------------------
  123. * ReserveSDRRepository
  124. *---------------------------------------*/
  125. int
  126. ReserveSDRRepository ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  127. {
  128. ReserveSDRRepositoryRes_T* pResSDRRepRes =
  129. ( ReserveSDRRepositoryRes_T*) pRes;
  130. /* Shouldnt allow to reserve when the SDR is in update mode */
  131. if( TRUE == g_BMCInfo.SDRConfig.UpdatingSDR )
  132. {
  133. pResSDRRepRes->CompletionCode = CC_SDR_REP_IN_UPDATE_MODE;
  134. return sizeof (pResSDRRepRes->CompletionCode);
  135. }
  136. pResSDRRepRes->ReservationID = SDR_ReserveSDRRepository ();
  137. g_BMCInfo.SDRConfig.PartAddbytes = 0;
  138. pResSDRRepRes->CompletionCode = CC_NORMAL;
  139. return sizeof (ReserveSDRRepositoryRes_T);
  140. }
  141. /*---------------------------------------
  142. * GetSDR
  143. *---------------------------------------*/
  144. int GetSDR ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  145. {
  146. SDRRecHdr_T* pSDRRec;
  147. GetSDRReq_T* pGetSDRReq = ( GetSDRReq_T*) pReq;
  148. GetSDRRes_T* pGetSDRRes = ( GetSDRRes_T*) pRes;
  149. uint8_t SDRLen = 0;
  150. if (TRUE != PreCheckSDRUpdateModeCmd (pRes))
  151. {
  152. return sizeof (uint8_t); /* error code set in func */
  153. }
  154. /* If the Offset is Not zero then its A partial get.. / if SDR is in update mode
  155. then check for the reservation id */
  156. if ((pGetSDRReq->Offset == 0) && (FALSE == g_BMCInfo.SDRConfig.UpdatingSDR ))
  157. {
  158. pSDRRec = GetSDRRec (pGetSDRReq->RecID);
  159. }
  160. else
  161. {
  162. pSDRRec = SDR_GetSDRRec ( pGetSDRReq->RecID, pGetSDRReq->ReservationID );
  163. }
  164. if (0 == pSDRRec)
  165. {
  166. pGetSDRRes->CompletionCode = g_BMCInfo.SDRConfig.SDRError;
  167. return sizeof (uint8_t);
  168. }
  169. SDRLen = pSDRRec->Len+sizeof(SDRRecHdr_T);
  170. if((0xFF == pGetSDRReq->Size) && (SDRLen >= pGetSDRReq->Offset))
  171. {
  172. pGetSDRReq->Size = SDRLen - pGetSDRReq->Offset;
  173. }
  174. /* Check for Max Request Bytes */
  175. if ((pGetSDRReq->Size > MAX_SDR_LEN) || (pGetSDRReq->Size > SDRLen) || (pGetSDRReq->Offset > SDRLen)
  176. || (pGetSDRReq->Size > (SDRLen-pGetSDRReq->Offset)))
  177. {
  178. pGetSDRRes->CompletionCode = CC_CANNOT_RETURN_REQ_BYTES;
  179. return sizeof (uint8_t);
  180. }
  181. /* Copy the response */
  182. pGetSDRRes->CompletionCode = CC_NORMAL;
  183. pGetSDRRes->NextRecID = SDR_GetNextSDRId (pSDRRec->ID);
  184. memcpy (pGetSDRRes + 1,
  185. (( uint8_t*) pSDRRec) + pGetSDRReq->Offset,
  186. pGetSDRReq->Size);
  187. return sizeof (GetSDRRes_T) + pGetSDRReq->Size;
  188. }
  189. /*---------------------------------------
  190. * AddSDR
  191. *---------------------------------------*/
  192. int
  193. AddSDR ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  194. {
  195. uint16_t RecID;
  196. SDRRecHdr_T* pSDRRec = ( SDRRecHdr_T*) pReq;
  197. AddSDRRes_T* pAddSDRRes = ( AddSDRRes_T*) pRes;
  198. /*Check the Minimum length of the SDR record*/
  199. if(ReqLen < sizeof(SDRRecHdr_T))
  200. {
  201. *pRes = CC_REQ_INV_LEN;
  202. return sizeof(uint8_t);
  203. }
  204. /*Check the SDR length*/
  205. if((ReqLen - sizeof(SDRRecHdr_T)) != pSDRRec->Len)
  206. {
  207. *pRes = CC_REQ_INV_LEN;
  208. return sizeof(uint8_t);
  209. }
  210. if (TRUE != PreCheckSDRUpdateModeCmd (pRes))
  211. {
  212. return sizeof (uint8_t); /* error code set in func */
  213. }
  214. RecID = SDR_AddSDRRec (pSDRRec);
  215. if (INVALID_RECORD_ID == RecID)
  216. {
  217. pAddSDRRes->CompletionCode = g_BMCInfo.SDRConfig.SDRError;
  218. return sizeof (pAddSDRRes->CompletionCode);
  219. }
  220. pAddSDRRes->CompletionCode = CC_NORMAL;
  221. pAddSDRRes->RecID = RecID;
  222. return sizeof (AddSDRRes_T);
  223. }
  224. /*---------------------------------------
  225. * PartialAddSDR
  226. *---------------------------------------*/
  227. int
  228. PartialAddSDR ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  229. {
  230. uint8_t Size;
  231. uint16_t RecID;
  232. PartialAddSDRReq_T* pPartialAddReq = ( PartialAddSDRReq_T*) pReq;
  233. PartialAddSDRRes_T* pPartialAddRes = ( PartialAddSDRRes_T*) pRes;
  234. if( ReqLen < sizeof(PartialAddSDRReq_T))
  235. {
  236. pPartialAddRes->CompletionCode = CC_REQ_INV_LEN;
  237. return sizeof (pPartialAddRes->CompletionCode);
  238. }
  239. /* Check for the reserved bytes should b zero */
  240. if ( 0 != (pPartialAddReq->Progress & RESERVED_BITS_PARTIALADDSDR ) )
  241. {
  242. pPartialAddRes->CompletionCode = CC_INV_DATA_FIELD;
  243. return sizeof(uint8_t);
  244. }
  245. if (TRUE != PreCheckSDRUpdateModeCmd (pRes))
  246. {
  247. return sizeof (uint8_t); /* error code set in func */
  248. }
  249. Size = ReqLen - sizeof (PartialAddSDRReq_T);
  250. if(0 == pPartialAddReq->Offset )
  251. {
  252. g_BMCInfo.SDRConfig.TrackPOffset =0;
  253. g_BMCInfo.SDRConfig.TrackRecID =pPartialAddReq->RecID;
  254. }
  255. else if((g_BMCInfo.SDRConfig.TrackPOffset) != pPartialAddReq->Offset || g_BMCInfo.SDRConfig.TrackRecID != pPartialAddReq->RecID)
  256. {
  257. pPartialAddRes->CompletionCode = CC_INV_DATA_FIELD;
  258. return sizeof (pPartialAddRes->CompletionCode);
  259. }
  260. RecID = SDR_PartialAddSDR (( uint8_t*)(pPartialAddReq + 1),
  261. pPartialAddReq->Offset,
  262. Size,
  263. pPartialAddReq->Progress & 0xf,
  264. pPartialAddReq->ReservationID);
  265. if (RecID == INVALID_RECORD_ID)
  266. {
  267. pPartialAddRes->CompletionCode = g_BMCInfo.SDRConfig.SDRError;
  268. return sizeof (pPartialAddRes->CompletionCode);
  269. }
  270. pPartialAddRes->CompletionCode = CC_NORMAL;
  271. pPartialAddRes->RecID = RecID;
  272. g_BMCInfo.SDRConfig.TrackPOffset +=Size;
  273. g_BMCInfo.SDRConfig.TrackRecID =RecID; //We are updating the available or alloted Record ID
  274. return sizeof (PartialAddSDRRes_T);
  275. }
  276. /*---------------------------------------
  277. * DeleteSDR
  278. *---------------------------------------*/
  279. int
  280. DeleteSDR ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  281. {
  282. printf("DeleteSDR not implement\r\n");
  283. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  284. // DeleteSDRReq_T* pDeleteSDRReq = ( DeleteSDRReq_T*)pReq;
  285. // DeleteSDRRes_T* pDeleteSDRRes = ( DeleteSDRRes_T*)pRes;
  286. // uint16_t RecID;
  287. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SDRConfig.SDRMutex, WAIT_INFINITE);
  288. // if (TRUE != PreCheckSDRUpdateModeCmd (pRes,BMCInst))
  289. // {
  290. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SDRConfig.SDRMutex);
  291. // return sizeof (uint8_t); /* error code set in func */
  292. // }
  293. // RecID=SDR_DeleteSDR ( pDeleteSDRReq->ReservationID, pDeleteSDRReq->RecID,BMCInst);
  294. // if(RecID == INVALID_RECORD_ID )
  295. // {
  296. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SDRConfig.SDRMutex);
  297. // pDeleteSDRRes->CompletionCode = g_BMCInfo[BMCInst].SDRConfig.SDRError;
  298. // return sizeof (pDeleteSDRRes->CompletionCode);
  299. // }
  300. // pDeleteSDRRes->CompletionCode = CC_NORMAL;
  301. // pDeleteSDRRes->RecID = RecID;
  302. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SDRConfig.SDRMutex);
  303. // // To send notification to CIM
  304. // if(g_PDKCIMEventHandle[PDKCIMEVENT_NOTIFYSERVERUPDATETOCIM] != NULL)
  305. // {
  306. // uint8 CMD;
  307. // // Set bits for SDR Event & Delete operation
  308. // CMD = 0x13;
  309. // ((int(*)(uint8, uint16))g_PDKCIMEventHandle[PDKCIMEVENT_NOTIFYSERVERUPDATETOCIM])(CMD, RecID);
  310. //
  311. // }
  312. return sizeof (DeleteSDRRes_T);
  313. }
  314. /*---------------------------------------
  315. * ClearSDRRepository
  316. *---------------------------------------*/
  317. int
  318. ClearSDRRepository ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  319. {
  320. int status;
  321. ClearSDRReq_T* pClrSDRReq = ( ClearSDRReq_T*) pReq;
  322. ClearSDRRes_T* pClrSDRRes = ( ClearSDRRes_T*) pRes;
  323. if (TRUE != PreCheckSDRUpdateModeCmd (pRes))
  324. {
  325. return sizeof (uint8_t); /* error code set in func */
  326. }
  327. if(pClrSDRReq->CLR[0] != 'C' || pClrSDRReq->CLR[1] != 'L' || pClrSDRReq->CLR[2] != 'R' )
  328. {
  329. pClrSDRRes->CompletionCode= CC_PASSWORD_TEST_FAILED;
  330. return sizeof(uint8_t);
  331. }
  332. status = SDR_ClearSDRRepository (pClrSDRReq->ReservationID,pClrSDRReq->InitOrStatus);
  333. if (0 != status)
  334. {
  335. pClrSDRRes->CompletionCode = g_BMCInfo.SDRConfig.SDRError;
  336. return sizeof (pClrSDRRes->CompletionCode);
  337. }
  338. pClrSDRRes->CompletionCode = CC_NORMAL;
  339. pClrSDRRes->EraseProgress = SDR_ERASE_COMPLETED;
  340. return sizeof (ClearSDRRes_T);
  341. }
  342. /*---------------------------------------
  343. * GetSDRRepositoryTime
  344. *---------------------------------------*/
  345. int
  346. GetSDRRepositoryTime ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  347. {
  348. //TODO
  349. uint32_t SDRTime = 0;
  350. GetSDRRepositoryTimeRes_T* pGetSDRTimeRes =
  351. ( GetSDRRepositoryTimeRes_T*) pRes;
  352. /* Get the time */
  353. // SDRTime = GetSelTimeStamp ();
  354. pGetSDRTimeRes->CompletionCode = CC_NORMAL;
  355. pGetSDRTimeRes->Time = SDRTime;
  356. return sizeof (GetSDRRepositoryTimeRes_T);
  357. }
  358. /*--------------------------------------
  359. * * SetSDRRepositoryTime
  360. * * -------------------------------------*/
  361. int
  362. SetSDRRepositoryTime ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  363. {
  364. //TODO
  365. SetSDRRepositoryTimeReq_T* pSetSDRTimeReq = ( SetSDRRepositoryTimeReq_T*) pReq;
  366. pSetSDRTimeReq->Time = (pSetSDRTimeReq->Time);
  367. //SET_SYSTEM_TIME_STAMP (&pSetSDRTimeReq->Time);
  368. /* Resetting the SELTimeUTCOffset to default value */
  369. // pBMCInfo->GenConfig.SELTimeUTCOffset = UNSPECIFIED_UTC_OFFSET;
  370. /*Write to NVRAM*/
  371. // FlushIPMI((uint8_t*)&pBMCInfo->GenConfig,(uint8_t*)&pBMCInfo->GenConfig,pBMCInfo->IPMIConfLoc.GenConfigAddr,
  372. // sizeof(GENConfig_T));
  373. pRes [0] = CC_NORMAL;
  374. return sizeof (*pRes);
  375. }
  376. /*---------------------------------------
  377. * EnterSDRUpdateMode
  378. *---------------------------------------*/
  379. int
  380. EnterSDRUpdateMode ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  381. {
  382. EnterSDRUpdateModeRes_T* pEnterSDRUpdateModeRes =
  383. ( EnterSDRUpdateModeRes_T*) pRes;
  384. g_BMCInfo.SDRConfig.UpdatingSDR = TRUE;
  385. g_BMCInfo.SDRConfig.UpdatingChannel = 0;//*curchannel & 0xF;
  386. pEnterSDRUpdateModeRes->CompletionCode = CC_NORMAL;
  387. return sizeof (EnterSDRUpdateModeRes_T);
  388. }
  389. /*------------------------------------------
  390. * ExitSDRUpdateMode
  391. *------------------------------------------*/
  392. int
  393. ExitSDRUpdateMode ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  394. {
  395. ExitSDRUpdateModeRes_T* pExitSDRUpdateModeRes =
  396. ( ExitSDRUpdateModeRes_T*) pRes;
  397. if (TRUE != PreCheckSDRUpdateModeCmd (pRes))
  398. {
  399. return sizeof (uint8_t); /* error code set in func */
  400. }
  401. g_BMCInfo.SDRConfig.UpdatingSDR = FALSE;
  402. pExitSDRUpdateModeRes->CompletionCode = CC_NORMAL;
  403. return sizeof (ExitSDRUpdateModeRes_T);
  404. }
  405. /*-------------------------------------------------
  406. * RunInitializationAgent
  407. *--------------------------------------------------*/
  408. int
  409. RunInitializationAgent ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  410. {
  411. printf("RunInitializationAgent not implement\r\n");
  412. // RunInitAgentRes_T* pRunInitAgentRes =
  413. // ( RunInitAgentRes_T*) pRes;
  414. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  415. // /* Reserved bit Checking */
  416. // if((pReq[0] & 0xFE) != 0x00)
  417. // {
  418. // pRes [0] = CC_INV_DATA_FIELD;
  419. // return sizeof (*pRes);
  420. // }
  421. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SDRConfig.SDRMutex, WAIT_INFINITE);
  422. // if (0 != pReq[0])
  423. // {
  424. // InitSDR (BMCInst);
  425. // SDRInitAgent (BMCInst);
  426. // // The sensor monitor loop has been made 0 for
  427. // // initializing the sensor scanning bit.
  428. // pBMCInfo->SenConfig.SensorMonitorLoopCount = 0;
  429. // }
  430. // pRunInitAgentRes->CompletionCode = CC_NORMAL;
  431. // pRunInitAgentRes->Status = SDR_INIT_COMPLETED;
  432. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SDRConfig.SDRMutex);
  433. return sizeof (RunInitAgentRes_T);
  434. }
  435. /*-----------------------------------------
  436. * GetSDRRec
  437. *-----------------------------------------*/
  438. SDRRecHdr_T*
  439. GetSDRRec (uint16_t RecID)
  440. {
  441. SDRRecHdr_T* pSDRRec;
  442. /* If ID == 0x0000 return first record */
  443. if (0 == RecID)
  444. {
  445. pSDRRec = SDR_GetFirstSDRRec ();
  446. if (0== pSDRRec) /* is SDR empty? */
  447. {
  448. g_BMCInfo.SDRConfig.SDRError = CC_SDR_REC_NOT_PRESENT;
  449. return 0;
  450. }
  451. return pSDRRec;
  452. }
  453. /* If ID == 0xFFFF return the last record */
  454. if (0xFFFF == RecID)
  455. {
  456. return GetLastSDRRec ();
  457. }
  458. pSDRRec = SDR_GetFirstSDRRec ();
  459. while (TRUE)
  460. {
  461. if (0== pSDRRec)
  462. {
  463. g_BMCInfo.SDRConfig.SDRError = CC_SDR_REC_NOT_PRESENT;
  464. return 0;
  465. }
  466. if (pSDRRec->ID == RecID)
  467. {
  468. return pSDRRec;
  469. }
  470. pSDRRec = SDR_GetNextSDRRec (pSDRRec);
  471. }
  472. }
  473. /*-----------------------------------------------------
  474. * InitSDR
  475. *-----------------------------------------------------*/
  476. int InitSDR ()
  477. {
  478. // uint8_t* pSDRRec;
  479. // SDRRecHdr_T* pSDRRecord;
  480. // int i; /* Multi-LUN support index will have more than 256 sensors*/
  481. // uint8_t OEM_Recdata[MAX_OEM_REC_LEN];
  482. // BMCInfo_t* pBMCInfo = &g_BMCInfo;
  483. // pBMCInfo->SDRConfig.SDRRAM = ( SDRRepository_T*) GetSDRSELNVRAddr(NVRH_SDR, BMCInst);
  484. // pSDRRec = GetSDRSELNVRAddr (NVRH_SDR + sizeof(SDRRepository_T), BMCInst);
  485. // pBMCInfo->SDRConfig.SDRRAM->NumRecords = 0;
  486. // pBMCInfo->SDRConfig.LatestRecordID =0;
  487. // pBMCInfo->SDRConfig.SDRRAM->Size = 16; /* SDR Repository Header */
  488. //#if (0x01 == MARK_FOR_DELETION_SUPPORT)
  489. // pBMCInfo->SDRConfig.NumMarkedRecords= 0;
  490. //#endif
  491. // if (pBMCInfo->SDRConfig.RepositoryInfo.OpSupport & OVERFLOW_FLAG)
  492. // {
  493. // pBMCInfo->SDRConfig.RepositoryInfo.OpSupport &= ~OVERFLOW_FLAG;
  494. // }
  495. // printf ("Init SDR\n");
  496. // while (TRUE)
  497. // {
  498. //#if (0x01 == MARK_FOR_DELETION_SUPPORT)
  499. // if ((0x5A == (( E2ROMHdr_T*)pSDRRec)->Valid)
  500. // || (0x01 == (( E2ROMHdr_T*)pSDRRec)->Valid) )
  501. // {
  502. // //count the records marked for deletion.
  503. // if (0x01 == (( E2ROMHdr_T*)pSDRRec)->Valid)
  504. // {
  505. // pBMCInfo->SDRConfig.NumMarkedRecords++;
  506. // }
  507. // else
  508. // {
  509. // pBMCInfo->SDRConfig.SDRRAM->NumRecords ++;
  510. // }
  511. //#else
  512. // if (0x5A == (( E2ROMHdr_T*)pSDRRec)->Valid)
  513. // {
  514. // pBMCInfo->SDRConfig.SDRRAM->NumRecords ++;
  515. //#endif
  516. // pBMCInfo->SDRConfig.LatestRecordID = ((SDRRecHdr_T *)((( E2ROMHdr_T*)pSDRRec)+1))->ID;
  517. // pBMCInfo->SDRConfig.SDRRAM->Size += (( E2ROMHdr_T*)pSDRRec)->Len;
  518. // pSDRRec += (( E2ROMHdr_T*)pSDRRec)->Len;
  519. // }
  520. // /* if No more Records */
  521. // else
  522. // {
  523. // break;
  524. // }
  525. // }
  526. // /* Check if SDR (valid record count) Empty */
  527. // if (0 == pBMCInfo->SDRConfig.SDRRAM->NumRecords)
  528. // {
  529. //#if IPM_DEVICE == 1
  530. // pBMCInfo->Msghndlr.SelfTestByte |= GST_SDR_EMPTY;
  531. //#endif
  532. // printf ("SDR EMPTY \n");
  533. // }
  534. // /* Update the SDR Erase Time Stamp */
  535. // pBMCInfo->SDRConfig.RepositoryInfo.EraseTimeStamp = pBMCInfo->GenConfig.SDREraseTime ;
  536. // /* Update the repository information */
  537. // UpdateRepositoryInfo (BMCInst);
  538. // pSDRRecord = SDR_GetFirstSDRRec (BMCInst);
  539. // for (i=0; i < pBMCInfo->SDRConfig.SDRRAM->NumRecords && pSDRRecord != NULL; i++)
  540. // {
  541. // if ((OEM_SDRFRU_REC == pSDRRecord->Type)||(OEM_SDRNM_REC == pSDRRecord->Type))
  542. // {
  543. // uint8_t Rec_len;
  544. // Rec_len=pSDRRecord->Len ;
  545. // memcpy(OEM_Recdata , pSDRRecord ,sizeof(SDRRecHdr_T)+Rec_len);
  546. // if(g_PDKHandle[PDK_PROCESSOEMRECORD] != NULL)
  547. // {
  548. // ((void(*)(uint8_t *,int))g_PDKHandle[PDK_PROCESSOEMRECORD]) ((uint8_t*)&OEM_Recdata,BMCInst);
  549. // }
  550. // }
  551. // if(g_corefeatures.node_manager == ENABLED)
  552. // {
  553. // if(OEM_SDRNM_REC == pSDRRecord->Type)
  554. // {
  555. // OEM_NMRec_T* sonm;
  556. // sonm =(OEM_NMRec_T*) ( (UINT8*)pSDRRecord );
  557. // if(sonm->RecordSubType == OEM_SDR_NM_REC)
  558. // pBMCInfo->NMConfig.NMDevSlaveAddress = sonm->NMDevSlaveAddress;
  559. // }
  560. // }
  561. // if(g_PDKHandle[PDK_PROCESSSENSORDATARECORD] != NULL)
  562. // {
  563. // ((void(*)(uint8_t *,int))g_PDKHandle[PDK_PROCESSSENSORDATARECORD]) ((uint8_t*)pSDRRecord,BMCInst);
  564. // }
  565. // pSDRRecord = SDR_GetNextSDRRec (pSDRRecord,BMCInst);
  566. // }
  567. //
  568. // if(g_PDKHandle[PDK_AFTERSDRINIT] != NULL)
  569. // {
  570. // ((void(*)(uint8_t))g_PDKHandle[PDK_AFTERSDRINIT]) (BMCInst);
  571. // }
  572. return 0;
  573. }
  574. /*----------------------------------------------------------*
  575. * SDR_GetNextSDRId
  576. *----------------------------------------------------------*/
  577. uint16_t
  578. SDR_GetNextSDRId (uint16_t RecID)
  579. {
  580. SDRRecHdr_T* pSDRRec;
  581. pSDRRec = GetSDRRec(RecID);
  582. if (0 == pSDRRec)
  583. {
  584. return INVALID_RECORD_ID;
  585. }
  586. pSDRRec = SDR_GetNextSDRRec (pSDRRec);
  587. if (0 == pSDRRec)
  588. {
  589. /* return last record ID (0xFFFF) */
  590. printf (" No Records\n");
  591. return 0xFFFF;
  592. }
  593. else
  594. {
  595. return pSDRRec->ID;
  596. }
  597. }
  598. /*--------------------------------------------------
  599. * SDR_GetFirstSDRRec
  600. *--------------------------------------------------*/
  601. SDRRecHdr_T*
  602. SDR_GetFirstSDRRec ()
  603. {
  604. return ReadSDRRepository (NULL);
  605. }
  606. /*--------------------------------------------------
  607. * SDR_GetNextSDRRec
  608. *-------------------------------------------------*/
  609. SDRRecHdr_T*
  610. SDR_GetNextSDRRec ( SDRRecHdr_T* pSDRRec)
  611. {
  612. return ReadSDRRepository (pSDRRec);
  613. }
  614. /*--------------------------------------------------
  615. * ReadSDRRepository
  616. *-------------------------------------------------*/
  617. SDRRecHdr_T*
  618. ReadSDRRepository ( SDRRecHdr_T* pSDRRec)
  619. {
  620. E2ROMHdr_T* InternalHdr;
  621. // uint8_t SDRSize=0;
  622. if (pSDRRec == 0)
  623. {
  624. InternalHdr = ( E2ROMHdr_T*)(g_BMCInfo.pSDR + sizeof(SDRRepository_T));
  625. }
  626. else
  627. {
  628. InternalHdr = ( E2ROMHdr_T*)(( uint8_t*)pSDRRec + SDR_SIZE (pSDRRec));
  629. /* is address >= First free byte ? */
  630. if (( uint8_t*) InternalHdr >= ( uint8_t*)SDR_FIRST_FREE_BYTE() )
  631. {
  632. /* No more records to read */
  633. //log("No more records to read\r\n");
  634. return 0;
  635. }
  636. //log("Reading the next record of %x \r\n", pSDRRec->ID);
  637. }
  638. /* is SDR Empty ?*/
  639. if (g_BMCInfo.SDRConfig.SDRRAM->NumRecords == 0)
  640. {
  641. return 0;
  642. }
  643. #if (0x01 == MARK_FOR_DELETION_SUPPORT)
  644. /* Fetch a Valid SDR */
  645. while (TRUE)
  646. {
  647. if( InternalHdr->Valid == 0x5a )
  648. {
  649. printf("Returning Valid record ID %x \n", (( SDRRecHdr_T*)(InternalHdr+1))->ID );
  650. return (( SDRRecHdr_T*)(InternalHdr+1));
  651. }
  652. InternalHdr = ( E2ROMHdr_T*) (((uint8_t*)InternalHdr) + InternalHdr->Len);
  653. /* is address >= First free byte ? */
  654. if (( uint8_t*) InternalHdr >= ( uint8_t*)SDR_FIRST_FREE_BYTE(BMCInst) )
  655. {
  656. log("No more valid records found \n");
  657. return 0;
  658. }
  659. }
  660. #else
  661. return (( SDRRecHdr_T*)(InternalHdr+1));
  662. #endif
  663. }
  664. /*--------------------------------------------------
  665. * WriteSDRRepository
  666. *-------------------------------------------------*/
  667. void
  668. WriteSDRRepository ( SDRRecHdr_T* pSDRRec, uint8_t Offset, uint8_t Size,uint8_t SdrSize)
  669. {
  670. //TODO:
  671. printf("WriteSDRRepository not implement\r\n");
  672. // E2ROMHdr_T* InternalHdr = ( E2ROMHdr_T *)SDR_FIRST_FREE_BYTE(BMCInst);
  673. // uint8_t* WriteAddr;
  674. // /* Update Validity and Length */
  675. // if ( Offset < sizeof(SDRRecHdr_T ) && ((Offset + Size) >= sizeof(SDRRecHdr_T)) )
  676. // {
  677. // InternalHdr->Valid = 0x5A;
  678. // InternalHdr->Len = SdrSize;
  679. // }
  680. // WriteAddr = ( uint8_t*)(InternalHdr+1);
  681. // memset((WriteAddr + Offset),0,SdrSize);
  682. // _fmemcpy ((WriteAddr + Offset), pSDRRec, Size);
  683. return ;
  684. }
  685. /**
  686. * @brief Check the SDR update mode.
  687. * @param pRes - Response.
  688. * @return TRUE/FALSE
  689. **/
  690. static uint8_t
  691. PreCheckSDRUpdateModeCmd ( uint8_t* pRes)
  692. {
  693. //TODO: when update SDR return FALSE.
  694. return TRUE;
  695. }
  696. /**
  697. * @brief Reserve the SDR Repository.
  698. * @return Reservation ID.
  699. **/
  700. static uint16_t
  701. SDR_ReserveSDRRepository ()
  702. {
  703. if (0xffff == g_BMCInfo.SDRConfig.ReservationID)
  704. {
  705. g_BMCInfo.SDRConfig.ReservationID = 1;
  706. }else
  707. {
  708. g_BMCInfo.SDRConfig.ReservationID++;
  709. }
  710. g_BMCInfo.SDRConfig.TrackPOffset =0;
  711. return g_BMCInfo.SDRConfig.ReservationID;
  712. }
  713. /**
  714. * @brief Get an SDR record.
  715. * @param RecID - SDR record ID.
  716. * @param ReservationID - SDR Reservation ID.
  717. * @return SDR record.
  718. **/
  719. static SDRRecHdr_T*
  720. SDR_GetSDRRec (uint16_t RecID, uint16_t ReservationID)
  721. {
  722. /* Bail out with error, if both the conditions are False (Reservation not valid)
  723. 1. Reservation ID matches, not equal to 0x00 & SDR is not in Update mode /
  724. 2. SDR is in Update mode & Reservation ID equals to 0x00
  725. */
  726. if ( !(((g_BMCInfo.SDRConfig.ReservationID == ReservationID) && (0x00 != ReservationID) &&
  727. (FALSE == g_BMCInfo.SDRConfig.UpdatingSDR)) || ((TRUE == g_BMCInfo.SDRConfig.UpdatingSDR) &&
  728. (0x00 == ReservationID))))
  729. {
  730. if( TRUE == g_BMCInfo.SDRConfig.UpdatingSDR )
  731. {
  732. g_BMCInfo.SDRConfig.SDRError = CC_SDR_REP_IN_UPDATE_MODE;
  733. }else /* Reservation ID doesn't match, return invalid reservation ID */
  734. {
  735. g_BMCInfo.SDRConfig.SDRError = CC_INV_RESERVATION_ID;
  736. }
  737. return 0;
  738. }
  739. return GetSDRRec (RecID);
  740. }
  741. //static uint8_t
  742. //ValidateSDRSize (uint8_t SDRType, uint8_t Size)
  743. //{
  744. // //TODO:
  745. // printf("ValidateSDRSize not implement\r\n");
  746. // int i;
  747. // IPMI_DBG_PRINT_2("ValidateSDR Type : 0x%X, Size : 0x%X\n", SDRType, Size);
  748. // if ((SDRType == OEM_SDRFRU_REC)||(SDRType == OEM_SDRNM_REC))
  749. // return TRUE;
  750. // for (i = 0; i < sizeof (SDRSize)/ 2; i++)
  751. // {
  752. // if ((SDRSize[i][0] == SDRType) && (SDRSize[i][1] >= Size))
  753. // {
  754. // return TRUE;
  755. // }
  756. // }
  757. // return FALSE;
  758. // return TRUE;
  759. //}
  760. /**
  761. * @brief Add an SDR record.
  762. * @param pSDRRec - SDR record.
  763. * @return Record ID.
  764. **/
  765. static uint16_t
  766. SDR_AddSDRRec ( SDRRecHdr_T* pSDRRec)
  767. {
  768. //TODO
  769. printf("SDR_AddSDRRec not implement\r\n");
  770. // uint16_t SDRSize;
  771. // uint8_t AllocSize;
  772. // int nRet;
  773. // if (FALSE == ValidateSDRSize(pSDRRec->Type, pSDRRec->Len + sizeof (SDRRecHdr_T)))
  774. // {
  775. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_REQ_INV_LEN;
  776. // return INVALID_RECORD_ID;
  777. // }
  778. //
  779. // AllocSize = SDR_SIZE (pSDRRec) + sizeof(E2ROMHdr_T);
  780. // if(0 != (AllocSize % SDR_ALLOC_UNIT_SIZE))
  781. // {
  782. // SDRSize = AllocSize + (SDR_ALLOC_UNIT_SIZE -(AllocSize % SDR_ALLOC_UNIT_SIZE));
  783. // }
  784. // else
  785. // {
  786. // SDRSize = AllocSize;
  787. // }
  788. // if (SDRSize > htoipmi_u16 (g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.FreeSpace))
  789. // {
  790. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport |= OVERFLOW_FLAG;
  791. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_OUT_OF_SPACE;
  792. // return INVALID_RECORD_ID;
  793. // }
  794. // /* Update the record ID */
  795. // pSDRRec->ID = g_BMCInfo[BMCInst].SDRConfig.LatestRecordID + 1;
  796. // /* Add this record to the end of the repository */
  797. // WriteSDRRepository (pSDRRec, 0, SDR_SIZE (pSDRRec),SDRSize,BMCInst);
  798. // /* Flush the sdr */
  799. // FlushSDR (SDR_FIRST_FREE_BYTE(BMCInst), SDRSize, nRet,BMCInst);
  800. //#if IPM_DEVICE == 1
  801. // if (-1 == nRet)
  802. // {
  803. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte |= GST_CANNOT_ACCESS_SDR;
  804. // }
  805. // else
  806. // {
  807. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_CANNOT_ACCESS_SDR;
  808. // }
  809. //#endif
  810. // /* Update the fields in SDR Repository */
  811. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->NumRecords++;
  812. // g_BMCInfo[BMCInst].SDRConfig.LatestRecordID++;
  813. //#if IPM_DEVICE == 1
  814. // if (g_BMCInfo[BMCInst].Msghndlr.SelfTestByte & GST_SDR_EMPTY)
  815. // {
  816. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_SDR_EMPTY;
  817. // }
  818. //#endif
  819. //
  820. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->Size += SDRSize;
  821. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->AddTimeStamp = GetSelTimeStamp(BMCInst);
  822. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.AddTimeStamp = GetSelTimeStamp(BMCInst);
  823. // /* Update the repository info */
  824. // UpdateRepositoryInfo (BMCInst);
  825. // /* Invalidate Reservation ID if any */
  826. // SDR_ReserveSDRRepository (BMCInst);
  827. // return pSDRRec->ID;
  828. return 0;
  829. }
  830. /**
  831. * @brief Add partial SDR record.
  832. * @param SDRData - SDR Data.
  833. * @param Offset - SDR offset.
  834. * @param Size - Size of the data.
  835. * @param IsLast - Is this a last record?
  836. * @param ReservationID - SDR reservation id.
  837. * @return the record id.
  838. **/
  839. static uint16_t
  840. SDR_PartialAddSDR ( uint8_t* SDRData, uint8_t Offset, uint8_t Size,
  841. uint8_t IsLast, uint16_t ReservationID)
  842. {
  843. //TODO
  844. printf("SDR_PartialAddSDR not implement\r\n");
  845. // uint16_t RecID;
  846. // SDRRecHdr_T* pSDRRecInNVR;
  847. // uint8_t SdrSize=0;
  848. // int nRet;
  849. //
  850. // /* Bail out with error, if both the conditions are False (Reservation not valid)
  851. // 1. Reservation ID matches, not equal to 0x00 & SDR is not in Update mode /
  852. // 2. SDR is in Update mode & Reservation ID equals to 0x00
  853. // */
  854. // if ( !(((g_BMCInfo[BMCInst].SDRConfig.ReservationID == ReservationID) && (0x00 != ReservationID) && (FALSE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR)) ||
  855. // ((TRUE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR) && (0x00 == ReservationID))))
  856. // {
  857. // if( TRUE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR )
  858. // {
  859. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_SDR_REP_IN_UPDATE_MODE;
  860. // }else //Reservation ID doesn't match, return invalid reservation ID.
  861. // {
  862. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INV_RESERVATION_ID;
  863. // }
  864. // g_BMCInfo[BMCInst].SDRConfig.PartAddbytes=0;
  865. // return INVALID_RECORD_ID;
  866. // }
  867. // pSDRRecInNVR = ( SDRRecHdr_T*) (SDR_FIRST_FREE_BYTE(BMCInst) +
  868. // sizeof (E2ROMHdr_T));
  869. // RecID = g_BMCInfo[BMCInst].SDRConfig.LatestRecordID + 1;
  870. // /* If the header is received completely, validate the size */
  871. // if ((Offset + Size) >= sizeof(SDRRecHdr_T))
  872. // {
  873. // if ( Offset < sizeof(SDRRecHdr_T ))
  874. // {
  875. // SDRRecHdr_T SDRHdr;
  876. //
  877. // memcpy((uint8_t*)&SDRHdr, (uint8_t*)pSDRRecInNVR, Offset );
  878. // memcpy(((uint8_t*)&SDRHdr) + Offset, SDRData, sizeof(SDRRecHdr_T) - Offset);
  879. //
  880. // (( SDRRecHdr_T*) pSDRRecInNVR)->ID = SDRHdr.ID = RecID;
  881. // memcpy( SDRData, ((uint8_t*)&SDRHdr) + Offset, sizeof(SDRRecHdr_T) - Offset );
  882. //
  883. // if (FALSE == ValidateSDRSize(SDRHdr.Type, SDRHdr.Len + sizeof (SDRRecHdr_T)))
  884. // {
  885. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_REQ_INV_LEN;
  886. // return INVALID_RECORD_ID;
  887. // }
  888. // SdrSize = SDRHdr.Len + sizeof (SDRRecHdr_T) + sizeof (E2ROMHdr_T);
  889. // if(0 != (SdrSize % SDR_ALLOC_UNIT_SIZE))
  890. // {
  891. // SdrSize += (SDR_ALLOC_UNIT_SIZE - (SdrSize % SDR_ALLOC_UNIT_SIZE));
  892. // }
  893. // if (SdrSize > ipmitoh_u16 (g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.FreeSpace))
  894. // {
  895. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport |= OVERFLOW_FLAG;
  896. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_OUT_OF_SPACE;
  897. // return INVALID_RECORD_ID;
  898. // }
  899. // g_BMCInfo[BMCInst].SDRConfig.PartAddbytes = SdrSize;
  900. // if ((Offset + Size) > (SDRHdr.Len + sizeof (SDRRecHdr_T)))
  901. // {
  902. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INV_DATA_FIELD;
  903. // return INVALID_RECORD_ID;
  904. // }
  905. // }
  906. // else if ((Offset + Size) > (pSDRRecInNVR->Len + sizeof (SDRRecHdr_T)))
  907. // {
  908. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INV_DATA_FIELD;
  909. // return INVALID_RECORD_ID;
  910. // }
  911. // }
  912. // if ((IsLast == 1) && ((Offset + Size) != (pSDRRecInNVR->Len + sizeof (SDRRecHdr_T))))
  913. // {
  914. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INCOMPLETE_WRITTEN_BYTES;
  915. // return INVALID_RECORD_ID;
  916. // }
  917. // WriteSDRRepository (( SDRRecHdr_T*)SDRData, Offset, Size,SdrSize,BMCInst);
  918. //
  919. // /* If this is the last data update the data fields and flush. */
  920. // if (IsLast == 1)
  921. // {
  922. // /* Flush the sdr */
  923. // FlushSDR (SDR_FIRST_FREE_BYTE(BMCInst), g_BMCInfo[BMCInst].SDRConfig.PartAddbytes, nRet,BMCInst);
  924. //#if IPM_DEVICE == 1
  925. // if (-1 == nRet)
  926. // {
  927. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte |= GST_CANNOT_ACCESS_SDR;
  928. // }
  929. // else
  930. // {
  931. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_CANNOT_ACCESS_SDR;
  932. // }
  933. //#endif
  934. // /* Update the fields in SDR Repository */
  935. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->NumRecords ++;
  936. // g_BMCInfo[BMCInst].SDRConfig.LatestRecordID++;
  937. // g_BMCInfo[BMCInst].SDRConfig.TrackPOffset=0;
  938. //#if IPM_DEVICE == 1
  939. // if (g_BMCInfo[BMCInst].Msghndlr.SelfTestByte & GST_SDR_EMPTY)
  940. // {
  941. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_SDR_EMPTY;
  942. // }
  943. //#endif
  944. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->Size += g_BMCInfo[BMCInst].SDRConfig.PartAddbytes;
  945. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->AddTimeStamp = GetSelTimeStamp(BMCInst);
  946. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.AddTimeStamp = GetSelTimeStamp(BMCInst);
  947. //
  948. // /* Update the repository info */
  949. // UpdateRepositoryInfo (BMCInst);
  950. // g_BMCInfo[BMCInst].SDRConfig.PartAddbytes =0;
  951. // /* Invalidate Reservation ID if any */
  952. // SDR_ReserveSDRRepository (BMCInst);
  953. // // To send notification to CIM
  954. // if(g_PDKCIMEventHandle[PDKCIMEVENT_NOTIFYSERVERUPDATETOCIM] != NULL)
  955. // {
  956. // uint8 CMD;
  957. // // Set bits for SDR Event & Add operation
  958. // CMD = 0x11;
  959. // ((int(*)(uint8, uint16))g_PDKCIMEventHandle[PDKCIMEVENT_NOTIFYSERVERUPDATETOCIM])(CMD, RecID);
  960. // }
  961. // }
  962. // return RecID;
  963. return 0;
  964. }
  965. ///**
  966. // * @brief Delete the SDR.
  967. // * @param ReservationID - SDR reservation id.
  968. // * @param RecordID - SDR Record ID, which needs to be deleted
  969. // * @return 0 if success, -1 if error.
  970. //**/
  971. //static uint16_t
  972. //SDR_DeleteSDR (uint16_t ReservationID, uint16_t RecID)
  973. //{
  974. // //TODO:
  975. // printf("SDR_DeleteSDR not implement\r\n");
  976. // //#define MARK_FOR_DELETION
  977. // SDRRecHdr_T* pSDRRec = NULL;
  978. // int nRet;
  979. // BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  980. //#if (0x01 == MARK_FOR_DELETION_SUPPORT)
  981. // E2ROMHdr_T* pRec = NULL;
  982. //#else
  983. // uint8_t* pDestLocation = NULL;
  984. // uint8_t* pSrcData = NULL;
  985. // uint8_t* pFreeBytes= NULL;
  986. // uint8_t deleteSDR_Size;
  987. // uint16_t size;
  988. //#endif
  989. // /* Bail out with error, if both the conditions are False (Reservation not valid)
  990. // 1. Reservation ID matches, not equal to 0x00 & SDR is not in Update mode /
  991. // 2. SDR is in Update mode & Reservation ID equals to 0x00
  992. // */
  993. // if ( !(((g_BMCInfo[BMCInst].SDRConfig.ReservationID == ReservationID) && (0x00 != ReservationID) && (FALSE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR)) ||
  994. // ((TRUE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR) && (0x00 == ReservationID))))
  995. // {
  996. // if( TRUE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR )
  997. // {
  998. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_SDR_REP_IN_UPDATE_MODE;
  999. // }else /* Reservation ID doesn't match, return invalid reservation ID */
  1000. // {
  1001. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INV_RESERVATION_ID;
  1002. // }
  1003. // return INVALID_RECORD_ID;
  1004. // }
  1005. // while(TRUE)
  1006. // {
  1007. // pSDRRec = ReadSDRRepository(pSDRRec,BMCInst);
  1008. // if (pSDRRec == 0)
  1009. // {
  1010. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_SDR_REC_NOT_PRESENT;
  1011. // return INVALID_RECORD_ID;
  1012. // }
  1013. // if (pSDRRec->ID == RecID)
  1014. // {
  1015. //#if (0x01 == MARK_FOR_DELETION_SUPPORT)
  1016. // pRec = ((E2ROMHdr_T *) pSDRRec) -1;
  1017. // pRec->Valid = 0x01; /* Mark this record for deletion */
  1018. // FlushSDR((uint8_t *)pRec, sizeof(pRec->Valid), nRet,BMCInst);
  1019. //#if IPM_DEVICE == 1
  1020. // if (-1 == nRet)
  1021. // {
  1022. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte |= GST_CANNOT_ACCESS_SDR;
  1023. // }
  1024. // else
  1025. // {
  1026. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_CANNOT_ACCESS_SDR;
  1027. // }
  1028. //#endif
  1029. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->NumRecords--;
  1030. // g_BMCInfo[BMCInst].SDRConfig.NumMarkedRecords++;
  1031. //#else
  1032. // /* Delete SDR - delete the current SDR, and rearrange the subsequent SDR's */
  1033. // pDestLocation = (uint8_t*)(((E2ROMHdr_T *) pSDRRec) -1);
  1034. // deleteSDR_Size = (((E2ROMHdr_T *) pSDRRec) -1)->Len;
  1035. // pSrcData = pDestLocation + deleteSDR_Size;
  1036. // pFreeBytes = (uint8_t*)SDR_FIRST_FREE_BYTE(BMCInst);
  1037. // size = ( uint8_t*) pFreeBytes - ( uint8_t*)pDestLocation;
  1038. // _fmemcpy (pDestLocation, pSrcData, size-deleteSDR_Size);
  1039. // _fmemset ((pFreeBytes - deleteSDR_Size), '\0', deleteSDR_Size );
  1040. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->Size -= deleteSDR_Size;
  1041. // FlushSDR(pDestLocation, size, nRet,BMCInst);
  1042. //#if IPM_DEVICE == 1
  1043. // if (-1 == nRet)
  1044. // {
  1045. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte |= GST_CANNOT_ACCESS_SDR;
  1046. // }
  1047. // else
  1048. // {
  1049. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_CANNOT_ACCESS_SDR;
  1050. // }
  1051. //#endif
  1052. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->NumRecords--;
  1053. //#endif
  1054. // /* Update the SDR Erase Timestamp */
  1055. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->EraseTimeStamp = GetSelTimeStamp (BMCInst);
  1056. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.EraseTimeStamp = GetSelTimeStamp(BMCInst);
  1057. // /* Store the SDR Ease Time Stamp in NVR */
  1058. // pBMCInfo->GenConfig.SDREraseTime = g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.EraseTimeStamp;
  1059. // FlushIPMI((uint8_t*)&pBMCInfo->GenConfig,(uint8_t*)&pBMCInfo->GenConfig,pBMCInfo->IPMIConfLoc.GenConfigAddr,
  1060. // sizeof(GENConfig_T),BMCInst);
  1061. // /* Update the repository info */
  1062. // UpdateRepositoryInfo (BMCInst);
  1063. // /* Invalidate Reservation ID if any */
  1064. // SDR_ReserveSDRRepository (BMCInst);
  1065. // return RecID;
  1066. // }
  1067. // }
  1068. //return 0;
  1069. //}
  1070. /**
  1071. * @brief Clear the SDR repository.
  1072. * @param ReservationID - SDR reservation id.
  1073. * @param InitOrStatus - Initiate erase or get status flag
  1074. * @return 0 if success, -1 if error.
  1075. **/
  1076. static int
  1077. SDR_ClearSDRRepository (uint16_t ReservationID, uint8_t InitOrStatus)
  1078. {
  1079. //TODO:
  1080. printf("SDR_ClearSDRRepository not implement\r\n");
  1081. // int nRet;
  1082. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1083. // /* Bail out with error, if both the conditions are False (Reservation not valid)
  1084. // 1. Reservation ID matches, not equal to 0x00 & SDR is not in Update mode /
  1085. // 2. SDR is in Update mode & Reservation ID equals to 0x00
  1086. // */
  1087. // if ( !(((g_BMCInfo[BMCInst].SDRConfig.ReservationID == ReservationID) && (0x00 != ReservationID) && (FALSE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR)) ||
  1088. // ((TRUE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR) && (0x00 == ReservationID))))
  1089. // {
  1090. // if( TRUE == g_BMCInfo[BMCInst].SDRConfig.UpdatingSDR )
  1091. // {
  1092. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_SDR_REP_IN_UPDATE_MODE;
  1093. // }else //Reservation ID doesn't match, return invalid reservation ID.
  1094. // {
  1095. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INV_RESERVATION_ID;
  1096. // }
  1097. // return -1;
  1098. // }
  1099. // // AAh = initiate erase, 00h = get erasure status.
  1100. // if (InitOrStatus != CLEAR_SDR_INITIATE_ERASE &&
  1101. // InitOrStatus != CLEAR_SDR_GET_STATUS)
  1102. // {
  1103. // g_BMCInfo[BMCInst].SDRConfig.SDRError = CC_INV_DATA_FIELD;
  1104. // return -1;
  1105. // }
  1106. // else if (InitOrStatus == CLEAR_SDR_GET_STATUS)
  1107. // {
  1108. // return 0;
  1109. // }
  1110. // _fmemset ((( uint8_t*)g_BMCInfo[BMCInst].SDRConfig.SDRRAM + 16), 0xFF,(pBMCInfo->IpmiConfig.SDRAllocationSize * 1024) - 16 );
  1111. // /* Flush the NVRAM */
  1112. // FlushSDR (g_BMCInfo[BMCInst].SDRConfig.SDRRAM, (pBMCInfo->IpmiConfig.SDRAllocationSize * 1024), nRet,BMCInst);
  1113. //#if IPM_DEVICE == 1
  1114. // if (-1 == nRet)
  1115. // {
  1116. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte |= GST_CANNOT_ACCESS_SDR;
  1117. // }
  1118. // else
  1119. // {
  1120. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte &= ~GST_CANNOT_ACCESS_SDR;
  1121. // }
  1122. //#endif
  1123. // /* Clear the fields of the SDR */
  1124. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->NumRecords = 0;
  1125. // g_BMCInfo[BMCInst].SDRConfig.LatestRecordID =0;
  1126. //#if (0x01 == MARK_FOR_DELETION_SUPPORT)
  1127. // g_BMCInfo[BMCInst].SDRConfig.NumMarkedRecords=0;
  1128. //#endif
  1129. // if (g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport & OVERFLOW_FLAG)
  1130. // {
  1131. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport &= ~OVERFLOW_FLAG;
  1132. // }
  1133. //#if IPM_DEVICE == 1
  1134. // g_BMCInfo[BMCInst].Msghndlr.SelfTestByte |= GST_SDR_EMPTY;
  1135. //#endif
  1136. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->Size = 16;
  1137. // g_BMCInfo[BMCInst].SDRConfig.SDRRAM->EraseTimeStamp = GetSelTimeStamp (BMCInst);
  1138. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.EraseTimeStamp = GetSelTimeStamp(BMCInst);
  1139. // /* Store the SDR Ease Time Stamp in NVR */
  1140. // pBMCInfo->GenConfig.SDREraseTime = g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.EraseTimeStamp;
  1141. // FlushIPMI((uint8_t*)&pBMCInfo->GenConfig,(uint8_t*)&pBMCInfo->GenConfig,pBMCInfo->IPMIConfLoc.GenConfigAddr,
  1142. // sizeof(GENConfig_T),BMCInst);
  1143. // /* Update the Repository Info */
  1144. // UpdateRepositoryInfo (BMCInst);
  1145. // /* Invalidate Reservation ID if any */
  1146. // SDR_ReserveSDRRepository (BMCInst);
  1147. return 0;
  1148. }
  1149. /**
  1150. * @brief Get the last SDR record.
  1151. * @return the last SDR record.
  1152. **/
  1153. static SDRRecHdr_T*
  1154. GetLastSDRRec ()
  1155. {
  1156. SDRRecHdr_T* pSDRRec;
  1157. pSDRRec = SDR_GetFirstSDRRec ();
  1158. while (TRUE)
  1159. {
  1160. SDRRecHdr_T* pCurSDRRec;
  1161. /* Save this record and get the next record */
  1162. pCurSDRRec = pSDRRec;
  1163. pSDRRec = SDR_GetNextSDRRec (pSDRRec);
  1164. /* If we have reached past the last return the last record */
  1165. if (0 == pSDRRec)
  1166. {
  1167. return pCurSDRRec;
  1168. }
  1169. }
  1170. }
  1171. ///**
  1172. // * @brief Update SDR repository information.
  1173. //**/
  1174. //static void
  1175. //UpdateRepositoryInfo ()
  1176. //{
  1177. // //TODO:
  1178. // printf("UpdateRepositoryInfo not implement\r\n");
  1179. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1180. // /* Update the version */
  1181. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.Version = SDR_VERSION;
  1182. // /* Update the record count */
  1183. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.RecCt = htoipmi_u16 (g_BMCInfo[BMCInst].SDRConfig.SDRRAM->NumRecords);
  1184. // /* Update the free space available */
  1185. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.FreeSpace = htoipmi_u16 (((pBMCInfo->IpmiConfig.SDRAllocationSize * 1024) - g_BMCInfo[BMCInst].SDRConfig.SDRRAM->Size));
  1186. // /* Update the the operation support */
  1187. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport=NO_SUPPORT;
  1188. // if(g_PDKCmdsHandle[PDKCMDS_PDKISCOMMANDENABLED]!= NULL)
  1189. // {
  1190. // if(((int(*)(uint8_t,uint8_t*,uint8_t,int))g_PDKCmdsHandle[PDKCMDS_PDKISCOMMANDENABLED])(NETFN_STORAGE,NULL,CMD_RESERVE_SDR_REPOSITORY,BMCInst) == 0)
  1191. // {
  1192. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport|=RESERVE_SDR_SUPPORT;
  1193. // }
  1194. // if(((int(*)(uint8_t,uint8_t*,uint8_t,int))g_PDKCmdsHandle[PDKCMDS_PDKISCOMMANDENABLED])(NETFN_STORAGE,NULL,CMD_GET_SDR_REPOSITORY_ALLOCATION_INFO,BMCInst) == 0)
  1195. // {
  1196. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport|=NON_MODAL_SUPPORT+GET_SDR_REPOSITORY_ALLOC_SUPPORT;
  1197. // }
  1198. // if(((int(*)(uint8_t,uint8_t*,uint8_t,int))g_PDKCmdsHandle[PDKCMDS_PDKISCOMMANDENABLED])(NETFN_STORAGE,NULL,CMD_PARTIAL_ADD_SDR,BMCInst) == 0)
  1199. // {
  1200. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport|=PARTIAL_ADD_SDR_SUPPORT;
  1201. // }
  1202. // if(((int(*)(uint8_t,uint8_t*,uint8_t,int))g_PDKCmdsHandle[PDKCMDS_PDKISCOMMANDENABLED])(NETFN_STORAGE,NULL,CMD_DELETE_SDR,BMCInst) == 0)
  1203. // {
  1204. // g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.OpSupport|=DELETE_SDR_SUPPORT;
  1205. // }
  1206. // }
  1207. // /* Update the repository allocation information */
  1208. // g_BMCInfo[BMCInst].SDRConfig.RepositoryAllocInfo.NumAllocUnits = htoipmi_u16 (((pBMCInfo->IpmiConfig.SDRAllocationSize * 1024) - 16) / SDR_ALLOC_UNIT_SIZE); /* Because 16 bytes are reserved for header info */
  1209. // g_BMCInfo[BMCInst].SDRConfig.RepositoryAllocInfo.AllocUnitSize = htoipmi_u16 (SDR_ALLOC_UNIT_SIZE);
  1210. // g_BMCInfo[BMCInst].SDRConfig.RepositoryAllocInfo.NumFreeAllocUnits = htoipmi_u16 (ipmitoh_u16 (g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.FreeSpace) /
  1211. // SDR_ALLOC_UNIT_SIZE);
  1212. // g_BMCInfo[BMCInst].SDRConfig.RepositoryAllocInfo.LargestFreeBlock = htoipmi_u16 (ipmitoh_u16 (g_BMCInfo[BMCInst].SDRConfig.RepositoryInfo.FreeSpace) /
  1213. // SDR_ALLOC_UNIT_SIZE);
  1214. // g_BMCInfo[BMCInst].SDRConfig.RepositoryAllocInfo.MaxRecSize = SDR_MAX_RECORD_SIZE / SDR_ALLOC_UNIT_SIZE;
  1215. //}
  1216. ///**
  1217. // * @brief SDR initialization agent.
  1218. //**/
  1219. //static void
  1220. //SDRInitAgent ()
  1221. //{
  1222. // //TODO:
  1223. // printf("SDRInitAgent not implement\r\n");
  1224. // uint8_t i,Count =0;
  1225. // uint8_t CmdRes [MAX_RES_LEN];
  1226. // SDRRecHdr_T* pSDRRec;
  1227. // HQueue_T IfcQ;
  1228. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1229. // if(g_PDKHandle[PDK_BEFOREINITAGENT] != NULL)
  1230. // {
  1231. // if(-1 == ((int(*)(int))g_PDKHandle[PDK_BEFOREINITAGENT]) (BMCInst))
  1232. // {
  1233. // return;
  1234. // }
  1235. // }
  1236. //#if SET_EVENT_RECEIVER == 1
  1237. // /* Turn off Event Generation */
  1238. // {
  1239. // SetEvtRcvReq_T SetEvtRcvReq = { 0xFF, 0 };
  1240. // SetEventReceiver (( uint8_t*)&SetEvtRcvReq,
  1241. // sizeof (SetEvtRcvReq_T), CmdRes,BMCInst);
  1242. // }
  1243. //#endif
  1244. // /* Get the MMC Controller addresses*/
  1245. // pSDRRec = SDR_GetFirstSDRRec (BMCInst);
  1246. // if(0 != GetQueueHandle(LAN_IFC_Q,&IfcQ,BMCInst))
  1247. // {
  1248. // IPMI_WARNING("Error in getting LanIfcQ Handle \n");
  1249. // }
  1250. // for (i=0; i < pBMCInfo->SDRConfig.SDRRAM->NumRecords && pSDRRec != NULL; i++)
  1251. // {
  1252. // if(MANAGEMENT_DEV_LOC_REC == pSDRRec->Type)
  1253. // {
  1254. // MgmtCtrlrDevLocator_T* pMgmtDevLocRec = ( MgmtCtrlrDevLocator_T*)pSDRRec;
  1255. // if(pBMCInfo->IpmiConfig.BMCSlaveAddr != pMgmtDevLocRec->DevSlaveAddr )
  1256. // {
  1257. // pBMCInfo->MgmtTbl[Count].OWNERID=pMgmtDevLocRec->DevSlaveAddr;
  1258. // pBMCInfo->MgmtTbl[Count++].PowerNotification=pMgmtDevLocRec->PowerStateNotification;
  1259. // }
  1260. // }
  1261. // pSDRRec = SDR_GetNextSDRRec (pSDRRec,BMCInst);
  1262. // }
  1263. // pBMCInfo->MgmtTbl[Count].OWNERID= 0xff;
  1264. //#if SUPPORT_MULTI_CONTROLLER == 1
  1265. // /* Sending the Set Event Reciver Disable Command to all MMC in IPMB BUS */
  1266. // if(pBMCInfo->IpmiConfig.PrimaryIPMBSupport == 0x01)
  1267. // {
  1268. // for(i=0; i<Count; i++)
  1269. // {
  1270. // MsgPkt_T Req;
  1271. // memset(&Req,0,sizeof(MsgPkt_T));
  1272. // IPMIMsgHdr_T* pIPMIMsgHdr = (IPMIMsgHdr_T*)Req.Data;
  1273. // SetEvtRcvReq_T* SetEvtRcvReq = ( SetEvtRcvReq_T*) &Req.Data[sizeof(IPMIMsgHdr_T)];
  1274. // pIPMIMsgHdr->ResAddr =pBMCInfo->MgmtTbl[i].OWNERID;
  1275. // pIPMIMsgHdr->NetFnLUN = (NETFN_SENSOR<< 2) | BMC_LUN_00;
  1276. // pIPMIMsgHdr->ChkSum = ~(pIPMIMsgHdr->ResAddr + pIPMIMsgHdr->NetFnLUN) + 1;
  1277. // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  1278. // pBMCInfo->SDRConfig.IPMB_Seqnum++;
  1279. // if (pBMCInfo->SDRConfig.IPMB_Seqnum >= 0x3F) { pBMCInfo->SDRConfig.IPMB_Seqnum = 0xFF; }
  1280. // pIPMIMsgHdr->RqSeqLUN = pBMCInfo->SDRConfig.IPMB_Seqnum<< 2; /* Request Seq Num */
  1281. // pIPMIMsgHdr->RqSeqLUN |= BMC_LUN_00; /* LUN =00 */
  1282. // pIPMIMsgHdr->Cmd = CMD_SET_EVENT_RECEIVER;
  1283. // SetEvtRcvReq->RcvSlaveAddr =0xFF ;
  1284. // SetEvtRcvReq->RcvLUN =BMC_LUN_00;
  1285. // Req.Param=BRIDGING_REQUEST;
  1286. // Req.Channel=PRIMARY_IPMB_CHANNEL;
  1287. // Req.Data [sizeof (IPMIMsgHdr_T) + sizeof(SetEvtRcvReq_T)] =
  1288. // CalculateCheckSum2 (Req.Data, sizeof (IPMIMsgHdr_T) + sizeof(SetEvtRcvReq_T));
  1289. // Req.Size = sizeof(IPMIMsgHdr_T) + sizeof(SetEvtRcvReq_T) +1 ; //Plus 1 for Check sum
  1290. // /* Post Msg to IPMB task to send the set event receiver */
  1291. // if ( -1 != IfcQ )
  1292. // {
  1293. // if(0 != PostMsg(&Req, IPMB_PRIMARY_IFC_Q,BMCInst))
  1294. // {
  1295. // IPMI_WARNING ("SDR.c : Error posting message to IPMBIfc_Q\n");
  1296. // }
  1297. // pBMCInfo->MgmtTbl[i].Status =TRUE;
  1298. // }
  1299. // }
  1300. // }
  1301. //#endif
  1302. //#if SUPPORT_MULTI_CONTROLLER == 1
  1303. // /* Sending the Run Initalization Command to all MMC in IPMB BUS */
  1304. // if(pBMCInfo->IpmiConfig.PrimaryIPMBSupport == 0x01)
  1305. // {
  1306. // for(i=0; i<Count; i++)
  1307. // {
  1308. // MsgPkt_T Req;
  1309. // memset(&Req,0,sizeof(MsgPkt_T));
  1310. // IPMIMsgHdr_T* pIPMIMsgHdr = (IPMIMsgHdr_T*)Req.Data;
  1311. // pIPMIMsgHdr->ResAddr =pBMCInfo->MgmtTbl[i].OWNERID;
  1312. // pIPMIMsgHdr->NetFnLUN = (NETFN_STORAGE<< 2) | BMC_LUN_00;
  1313. // /* Get Device ID */
  1314. // // pIPMIMsgHdr->NetFnLUN = (NETFN_APP<< 2) | BMC_LUN_00;
  1315. // pIPMIMsgHdr->ChkSum = ~(pIPMIMsgHdr->ResAddr + pIPMIMsgHdr->NetFnLUN) + 1;
  1316. // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  1317. // Req.Channel=PRIMARY_IPMB_CHANNEL;
  1318. // g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum++;
  1319. // if (g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum >= 0x3F) { g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum = 0xFF; }
  1320. // pIPMIMsgHdr->RqSeqLUN = g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum<< 2; /* Request Seq Num */
  1321. // pIPMIMsgHdr->RqSeqLUN |= BMC_LUN_00; /* LUN =00 */
  1322. // Req.Param=BRIDGING_REQUEST;
  1323. // pIPMIMsgHdr->Cmd = CMD_RUN_INITIALIZATION_AGENT;
  1324. // Req.Data[sizeof(IPMIMsgHdr_T)]=0x1;
  1325. // Req.Data [sizeof (IPMIMsgHdr_T) + 1] =
  1326. // CalculateCheckSum2 (Req.Data, sizeof (IPMIMsgHdr_T) +1);
  1327. // Req.Size = sizeof(IPMIMsgHdr_T) + 2; //Plus 2 for req data's
  1328. // if ( -1 !=IfcQ )
  1329. // {
  1330. // if(0 != PostMsg(&Req, IPMB_PRIMARY_IFC_Q,BMCInst))
  1331. // {
  1332. // IPMI_WARNING ("SDR.c : Error posting message to IPMBIfc_Q\n");
  1333. // }
  1334. // pBMCInfo->MgmtTbl[i].Status =TRUE;
  1335. // }
  1336. // }
  1337. // }
  1338. //#endif
  1339. // pSDRRec = SDR_GetFirstSDRRec (BMCInst);
  1340. // for (i=0; i < pBMCInfo->SDRConfig.SDRRAM->NumRecords && pSDRRec != NULL; i++)
  1341. // {
  1342. // if (FULL_SDR_REC == pSDRRec->Type)
  1343. // {
  1344. // /* For all records of type 01h */
  1345. // FullSensorRec_T* pFullRec = ( FullSensorRec_T*)pSDRRec;
  1346. // uint16_t ValidMask = htoipmi_u16(0x0FFF);
  1347. // // If not a threshold sensor, then 15 event bits are used.
  1348. // if (pFullRec->EventTypeCode != 0x01)
  1349. // {
  1350. // ValidMask = htoipmi_u16(0x7FFF);
  1351. // }
  1352. // /* Disable Event & Scanning messages, if Disable is supported */
  1353. // if (0x03 != (pFullRec->SensorCaps & 0x03))
  1354. // {
  1355. // SetSensorEventEnableReq_T SetSEReq;
  1356. // // disable all events for sensor
  1357. // SetSEReq.SensorNum = pFullRec->SensorNum;
  1358. // SetSEReq.Flags = DISABLE_SELECTED_EVENT_MSG; // Event Disabled
  1359. // SetSEReq.AssertionMask = ValidMask;
  1360. // SetSEReq.DeAssertionMask = ValidMask;
  1361. // SetSensorEventEnable (( uint8_t*)&SetSEReq,
  1362. // sizeof (SetSensorEventEnableReq_T), CmdRes,BMCInst);
  1363. // }
  1364. // /* Set Sensor Type */
  1365. //#if SET_SENSOR_TYPE != UNIMPLEMENTED
  1366. // if (pFullRec->SensorInit & BIT2)
  1367. // {
  1368. // /* Set Sensor Type */
  1369. // SetSensorTypeReq_T SetSensorTypeReq;
  1370. // SetSensorTypeReq.SensorNum = pFullRec->SensorNum;
  1371. // SetSensorTypeReq.SensorType = pFullRec->SensorType;
  1372. // SetSensorTypeReq.EventTypeCode = pFullRec->EventTypeCode;
  1373. // SetSensorType (( uint8_t*)&SetSensorTypeReq, sizeof(SetSensorTypeReq), CmdRes,BMCInst);
  1374. // }
  1375. //#endif
  1376. // /* Set Sensor Thresholds */
  1377. // {
  1378. // SetSensorThresholdReq_T SetThresholdReq;
  1379. // SetThresholdReq.SensorNum = pFullRec->SensorNum;
  1380. // SetThresholdReq.SetFlags = ((pFullRec->DiscreteReadingMask >> 8) & 0x3F);
  1381. // if (pFullRec->SensorInit & BIT4)
  1382. // {
  1383. // SetThresholdReq.LowerNonCritical = pFullRec->LowerNonCritical;
  1384. // SetThresholdReq.LowerCritical = pFullRec->LowerCritical;
  1385. // SetThresholdReq.LowerNonRecoverable = pFullRec->LowerNonRecoverable;
  1386. // SetThresholdReq.UpperNonCritical = pFullRec->UpperNonCritical;
  1387. // SetThresholdReq.UpperCritical = pFullRec->UpperCritical;
  1388. // SetThresholdReq.UpperNonRecoverable = pFullRec->UpperNonRecoverable;
  1389. // SetSensorThresholds (( uint8_t*)&SetThresholdReq,
  1390. // sizeof (SetSensorThresholdReq_T), CmdRes,BMCInst);
  1391. // }
  1392. // }
  1393. // /* Set Sensor Hysteresis */
  1394. // {
  1395. // SetSensorHysterisisReq_T SetHysteresisReq;
  1396. // SetHysteresisReq.SensorNum = pFullRec->SensorNum;
  1397. // SetHysteresisReq.Reserved = 0;
  1398. // if (pFullRec->SensorInit & BIT3) //Added for DR#31091
  1399. // {
  1400. // SetHysteresisReq.PositiveHysterisis = pFullRec->PositiveHysterisis;
  1401. // SetHysteresisReq.NegativeHysterisis = pFullRec->NegativeHysterisis;
  1402. // SetSensorHysterisis (( uint8_t*)&SetHysteresisReq,
  1403. // sizeof (SetSensorHysterisisReq_T), CmdRes,BMCInst);
  1404. // }
  1405. // }
  1406. // /* Enable Event & Scanning messages, if Disabled */
  1407. // if (0x03 != (pFullRec->SensorCaps & 0x03))
  1408. // {
  1409. // SetSensorEventEnableReq_T SetSEReq;
  1410. // SetSEReq.SensorNum = pFullRec->SensorNum;
  1411. // SetSEReq.Flags = (pFullRec->SensorInit & BIT6) | ((pFullRec->SensorInit & BIT5) << 2) | ENABLE_SELECTED_EVENT_MSG; // Event Enabled
  1412. // SetSEReq.AssertionMask = (pFullRec->AssertionEventMask & ValidMask);
  1413. // SetSEReq.DeAssertionMask = (pFullRec->DeAssertionEventMask & ValidMask);
  1414. // SetSensorEventEnable (( uint8_t*)&SetSEReq,
  1415. // sizeof (SetSensorEventEnableReq_T), CmdRes,BMCInst);
  1416. // }
  1417. // }
  1418. // if (pSDRRec->Type == COMPACT_SDR_REC)
  1419. // {
  1420. // CompactSensorRec_T* pCompactRec = ( CompactSensorRec_T*)pSDRRec;
  1421. // uint16_t ValidMask = htoipmi_u16(0x0FFF);
  1422. // // If not a threshold sensor, then 15 event bits are used.
  1423. // if (pCompactRec->EventTypeCode != 0x01)
  1424. // {
  1425. // ValidMask = htoipmi_u16(0x7FFF);
  1426. // }
  1427. // /* Disable Event & Scanning messages, if Disable is supported */
  1428. // if (0x03 != (pCompactRec->SensorCaps & 0x03))
  1429. // {
  1430. // SetSensorEventEnableReq_T SetSEReq;
  1431. // SetSEReq.SensorNum = pCompactRec->SensorNum;
  1432. // SetSEReq.Flags = DISABLE_SELECTED_EVENT_MSG; // Event Disabled
  1433. // SetSEReq.AssertionMask = ValidMask;
  1434. // SetSEReq.DeAssertionMask = ValidMask;
  1435. // SetSensorEventEnable (( uint8_t*)&SetSEReq,
  1436. // sizeof (SetSensorEventEnableReq_T), CmdRes,BMCInst);
  1437. // }
  1438. // /* Set Sensor Type */
  1439. //#if SET_SENSOR_TYPE != UNIMPLEMENTED
  1440. // if (pCompactRec->SensorInit & BIT2)
  1441. // {
  1442. // /* Set Sensor Type */
  1443. // SetSensorTypeReq_T SetSensorTypeReq;
  1444. // SetSensorTypeReq.SensorNum = pCompactRec->SensorNum;
  1445. // SetSensorTypeReq.SensorType = pCompactRec->SensorType;
  1446. // SetSensorTypeReq.EventTypeCode = pCompactRec->EventTypeCode;
  1447. // SetSensorType (( uint8_t*)&SetSensorTypeReq, sizeof(SetSensorTypeReq), CmdRes,BMCInst);
  1448. // }
  1449. //#endif
  1450. // /* Set Sensor Hysteresis */
  1451. // {
  1452. // SetSensorHysterisisReq_T SetHysteresisReq;
  1453. // SetHysteresisReq.SensorNum = pCompactRec->SensorNum;
  1454. // SetHysteresisReq.Reserved = 0;
  1455. // SetHysteresisReq.PositiveHysterisis = pCompactRec->PositiveHysteris;
  1456. // SetHysteresisReq.NegativeHysterisis = pCompactRec->NegativeHysterisis;
  1457. // SetSensorHysterisis (( uint8_t*)&SetHysteresisReq,
  1458. // sizeof (SetSensorHysterisisReq_T), CmdRes,BMCInst);
  1459. // }
  1460. // /* Enable Event & Scanning messages, if Disabled */
  1461. // if (0x03 != (pCompactRec->SensorCaps & 0x03))
  1462. // {
  1463. // SetSensorEventEnableReq_T SetSEReq;
  1464. // SetSEReq.SensorNum = pCompactRec->SensorNum;
  1465. // SetSEReq.Flags = (pCompactRec->SensorInit & BIT6) | ((pCompactRec->SensorInit & BIT5) << 2) |ENABLE_SELECTED_EVENT_MSG ; // Event Enabled
  1466. // SetSEReq.AssertionMask = (pCompactRec->AssertionEventMask & ValidMask);
  1467. // SetSEReq.DeAssertionMask = (pCompactRec->DeAssertionEventMask & ValidMask);
  1468. // SetSensorEventEnable (( uint8_t*)&SetSEReq,
  1469. // sizeof (SetSensorEventEnableReq_T), CmdRes,BMCInst);
  1470. // }
  1471. // }
  1472. // pSDRRec = SDR_GetNextSDRRec (pSDRRec,BMCInst);
  1473. // }
  1474. //#if SET_EVENT_RECEIVER == 0
  1475. // /* Enable Event Generation */
  1476. // {
  1477. // SetEvtRcvReq_T SetEvtRcvReq = { 0x20, 0 };
  1478. // SetEventReceiver (( uint8_t*)&SetEvtRcvReq,
  1479. // sizeof (SetEvtRcvReq_T), CmdRes,BMCInst);
  1480. // }
  1481. //#endif
  1482. //#if SUPPORT_MULTI_CONTROLLER == 1
  1483. // /* Sending the Set Event Reciver enable Command to all MMC in IPMB BUS */
  1484. // for(i=0;i<Count;i++)
  1485. // {
  1486. // MsgPkt_T Req;
  1487. // IPMIMsgHdr_T* pIPMIMsgHdr = (IPMIMsgHdr_T*)Req.Data;
  1488. // SetEvtRcvReq_T* SetEvtRcvReq = ( SetEvtRcvReq_T*) &Req.Data[sizeof(IPMIMsgHdr_T)];
  1489. // pIPMIMsgHdr->ResAddr =pBMCInfo->MgmtTbl[i].OWNERID;
  1490. // pIPMIMsgHdr->NetFnLUN = (NETFN_SENSOR<< 2) | BMC_LUN_00;
  1491. // pIPMIMsgHdr->ChkSum = ~(pIPMIMsgHdr->ResAddr + pIPMIMsgHdr->NetFnLUN) + 1;
  1492. // pIPMIMsgHdr->ReqAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  1493. // Req.Channel=PRIMARY_IPMB_CHANNEL;
  1494. // g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum++;
  1495. // if (g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum >= 0x3F) { g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum = 0xFF; }
  1496. // pIPMIMsgHdr->RqSeqLUN = g_BMCInfo[BMCInst].SDRConfig.IPMB_Seqnum<< 2; /* Request Seq Num */
  1497. // pIPMIMsgHdr->RqSeqLUN |= BMC_LUN_00; /* LUN =00 */
  1498. // pIPMIMsgHdr->Cmd = CMD_SET_EVENT_RECEIVER;
  1499. // SetEvtRcvReq->RcvSlaveAddr = pBMCInfo->IpmiConfig.BMCSlaveAddr;
  1500. // SetEvtRcvReq->RcvLUN =BMC_LUN_00;
  1501. // Req.Param=BRIDGING_REQUEST;
  1502. // Req.Data [sizeof (IPMIMsgHdr_T) + sizeof(SetEvtRcvReq_T)] =
  1503. // CalculateCheckSum2 (Req.Data, sizeof (IPMIMsgHdr_T) + sizeof(SetEvtRcvReq_T));
  1504. // Req.Size = sizeof(IPMIMsgHdr_T) + sizeof(SetEvtRcvReq_T)+1; // plus 1 for checksum
  1505. // /* Post Msg to IPMB task to send the set event receiver */
  1506. // if ( -1 != IfcQ )
  1507. // {
  1508. // if(0 != PostMsg(&Req, IPMB_PRIMARY_IFC_Q,BMCInst))
  1509. // {
  1510. // IPMI_WARNING ("SDR.c : Error posting message to IPMBIfc_Q\n");
  1511. // }
  1512. // pBMCInfo->MgmtTbl[i].Status =TRUE;
  1513. // }
  1514. // //PDK_SMCDelay(pBMCInfo->MgmtTbl[i].OWNERID);
  1515. // //PDK_SMCDelay(0x40);
  1516. // //sleep(3);
  1517. // }
  1518. //#endif
  1519. // if(g_PDKHandle[PDK_AFTERINITAGENT] != NULL)
  1520. // {
  1521. // ((int(*)(uint8_t,int))g_PDKHandle[PDK_AFTERINITAGENT]) (CmdRes[0],BMCInst);
  1522. // }
  1523. // return;
  1524. //}
  1525. #endif /* SDR_DEVICE */