SDR.c 62 KB

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