SDR.c 62 KB

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