SDR.c 63 KB

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