Sensor.c 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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. *
  16. * sensor.c
  17. * Sensor functions.
  18. *
  19. * Author: Govind Kothandapani <govindk@ami.com>
  20. * Bakka Ravinder Reddy <bakkar@ami.com>
  21. ******************************************************************/
  22. #include "MsgHndlr.h"
  23. #include "sensor_tbl.h"
  24. #include "com_IPMI_Sensor.h"
  25. #include "Support.h"
  26. #include "Sensor.h"
  27. #include "SDRFunc.h"
  28. #include "SensorEvent.h"
  29. #include <string.h>
  30. #include "main.h"
  31. /* Reserved bit macro definitions */
  32. #define RESERVED_BITS_SETSENSORTYPE 0X80 //(BIT7)
  33. #define RESERVED_BITS_REARMSENSOR_REARMALLEVENTS 0X7F //(BIT6 | BIT5 | BIT4 | BIT3 | BIT2 | BIT1 | BIT0)
  34. #define RESERVED_BITS_REARMSENSOR_REARMASSEVT2_1 0XF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  35. #define RESERVED_BITS_REARMSENSOR_REARMDEASSEVT2_1 0XF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  36. #define RESERVED_BITS_REARMSENSOR_REARMASSEVT2_2 0X80 //(BIT7)
  37. #define RESERVED_BITS_REARMSENSOR_REARMDEASSEVT2_2 0X80 //(BIT7)
  38. #define RESERVED_BITS_SETSENSORTHRESHOLDS 0XC0 //(BIT7 | BIT6)
  39. #define RESERVED_BITS_SETSENEVTEN_FLAGS 0X0F //(BIT3 | BIT2 | BIT1 | BIT0)
  40. #define RESERVED_BITS_SETSENEVTEN_ASSERTIONMASK 0X8000
  41. #define RESERVED_BITS_SETSENEVTEN_DEASSERTIONMASK 0X8000
  42. #define RESERVED_BITS_SETSENRD_ASSEVTOCCBYTE_1 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  43. #define RESERVED_BITS_SETSENRD_DEASSEVTOCCBYTE_1 0xF0 //(BIT7 | BIT6 | BIT5 | BIT4)
  44. #define RESERVED_BITS_SETSENRD_ASSEVTOCCBYTE_2 0x80 //(BIT7)
  45. #define RESERVED_BITS_SETSENRD_DEASSEVTOCCBYTE_2 0x80 //(BIT7)
  46. #define SENSOR_THRESOLD_ACCESS_BITS 0x0c //(BIT2 | BIT3)
  47. #define SENSOR_HYSTERESIS_ACCESS_BITS 0x30 //(BIT4 | BIT5)
  48. #if SENSOR_DEVICE == 1
  49. /*** Local Definitions ***/
  50. //#define NUM_SENSORS() (g_BMCInfo.SenConfig.NumThreshSensors + g_BMCInfo.SenConfig.NumNonThreshSensors)
  51. #define FULL_SDR_REC 0x01
  52. #define COMPACT_SDR_REC 0x02
  53. #define OEM_SDR_FRU_REC 0xf1
  54. #define OEM_SDR_NM_REC 0x0D
  55. #define FL_STATIC_SENSOR 0x00
  56. #define FL_NUM_LUN(NUM_LUN) NUM_LUN
  57. #define LWR_NON_CRIT 0x01
  58. #define LWR_CRIT 0x02
  59. #define LWR_NON_REC 0x04
  60. #define UPR_NON_CRIT 0x08
  61. #define UPR_CRIT 0x10
  62. #define UPR_NON_REC 0x20
  63. #define EVENT_MSG_MASK 0x80
  64. #define SCAN_MASK 0x40
  65. #define ENABLE_DISABLE_EVENT_MASK 0x30
  66. #define DO_NOT_CHANGE 0x00
  67. #define ENABLE_SELECTED_EVENT_MSG 0x10
  68. #define DISABLE_SELECTED_EVENT_MSG 0x20
  69. #define CC_INVALID_ATTEMPT_TO_SET 0x80
  70. #define MIN_SET_SEN_READING_CMD_LEN 3
  71. #define LEN_FOR_EVT_DATA 10
  72. #define MAX_SET_SEN_READ_LEN 10
  73. #define LEN_FOR_ASSERT_DATA 5
  74. #define LEN_FOR_DEASSERT_DATA 7
  75. #define LEN_FOR_SETSENSOR_DATA 3
  76. #define NOT_FOUND_SCAN_DISABLED -1
  77. #define NOT_FOUND_SCAN_ENABLED -2
  78. #define ENTITY_FOUND 1
  79. #define ENTITY_NOT_FOUND 0
  80. #define DCMI_TEMP_READING 0x0
  81. #define DCMI_INST_NUMBER 0x1
  82. /*** Local typedefs ***/
  83. /**
  84. * @struct SR_SensorInfo_T
  85. * @brief Sensor Information.
  86. **/
  87. typedef struct
  88. {
  89. /* CAUTION Order of members dependent on Response structures */
  90. uint8_t M_LSB;
  91. uint8_t M_MSB_Tolerance;
  92. uint8_t B_LSB;
  93. uint8_t B_MSB_Accuracy;
  94. uint8_t Accuracy_MSB_Exp;
  95. uint8_t RExp_BExp;
  96. uint8_t PositiveHysterisis;
  97. uint8_t NegativeHysterisis;
  98. uint8_t LowerNonCritical;
  99. uint8_t LowerCritical;
  100. uint8_t LowerNonRecoverable;
  101. uint8_t UpperNonCritical;
  102. uint8_t UpperCritical;
  103. uint8_t UpperNonRecoverable;
  104. uint8_t EventFlags;
  105. uint16_t AssertionMask;
  106. uint16_t DeAssertionMask;
  107. uint8_t EventTypeCode;
  108. uint16_t ReadWriteThreshMask;
  109. uint8_t SensorInit;
  110. uint8_t SensorNum;
  111. } SR_SensorInfo_T;
  112. /*** Global Variables ***/
  113. // uint8_t g_NumThreshSensors;
  114. // uint8_t g_NumNonThreshSensors;
  115. // uint8_t g_FRUInfo[MAX_PDK_FRU_SUPPORTED];
  116. //FRUInfo_T *m_FRUInfo[MAX_PDK_FRU_SUPPORTED];
  117. //uint8_t m_total_frus=0;
  118. //Sensor-Type Sensor-specific-offset
  119. static const uint8_t sensor_presence [][2] = {
  120. {PROCESSOR, PROCESSOR_PRESENCE_DETECTED},
  121. {POWER_SUPPLY, POWER_SUPPLY_PRESENCE_DETECTED},
  122. {POWER_SUPPLY, POWER_SUPPLY_OUT_OF_RANGE_PRESENT},
  123. {MEMORY, MEMORY_PRESENCE_DETECTED},
  124. {ENTITY_PRESENCE, ENTITY_PRESENCE_ENTITY_PRESENT},
  125. {BATTERY, BATTERY_PRESENCE_DETECTED}
  126. };
  127. #define SENSOR_PRESENCE_COUNT (sizeof(sensor_presence)/ sizeof(sensor_presence[0]))
  128. /*** Prototype Declaration ***/
  129. //static void FindNumSensors (void);
  130. /*---------------------------------------
  131. * InitSensor
  132. *---------------------------------------*/
  133. int
  134. InitSensorInfo ()
  135. {
  136. SensorInfo_T* pSensorInfo;
  137. SensorSharedMem_T* pSMSharedMem;
  138. SDRRecHdr_T* pSDRRec;
  139. int i;
  140. pSMSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem;
  141. /* Update Sensor Properties & Get SDR & initialize sensors */
  142. for (i = 0; i < g_BMCInfo.SenConfig.ValidSensorCnt; i++)
  143. {
  144. pSensorInfo = (SensorInfo_T*)&pSMSharedMem->SensorInfo [i];
  145. g_BMCInfo.SenConfig.ValidSensorList[i] = sensor_tbl[i].sensor_number;
  146. gSensorHistoryInfo[i].SensorNum = sensor_tbl[i].sensor_number;
  147. pSensorInfo->SensorNumber = sensor_tbl[i].sensor_number;
  148. pSensorInfo->SensorReading = 0;
  149. pSensorInfo->SensorMonitorInterval = sensor_tbl[i].monitor_interval;
  150. pSensorInfo->SensorState = sensor_tbl[i].monitor_state;
  151. pSensorInfo->PowerOnDelay = sensor_tbl[i].poweron_delay;
  152. pSensorInfo->SysResetDelay = sensor_tbl[i].reset_delay;
  153. pSDRRec = SR_FindSDR(pSensorInfo->SensorNumber);
  154. SR_LoadSDRDefaults(pSDRRec, pSensorInfo);
  155. pSensorInfo->SDRRec = (SDRRecHdr_T*)pSDRRec;
  156. }
  157. return 0;
  158. }
  159. /*---------------------------------------
  160. * InitSensor
  161. *---------------------------------------*/
  162. int
  163. InitSensorDev ()
  164. {
  165. int i;
  166. sensor_tbl_t* pSensorDev = NULL;
  167. for(i=0;i<g_BMCInfo.SenConfig.ValidSensorCnt;i++)
  168. {
  169. pSensorDev = (sensor_tbl_t*)getSensorDev(g_BMCInfo.SenConfig.ValidSensorList[i]);
  170. pSensorDev->device_init();
  171. }
  172. return 0;
  173. }
  174. /*-----------------------------------------
  175. * SR_FindSDR
  176. *-----------------------------------------*/
  177. SDRRecHdr_T* SR_FindSDR (uint8_t SensorNum)
  178. {
  179. SDRRecHdr_T* sr = SDR_GetFirstSDRRec ();
  180. FullSensorRec_T* sfs = NULL;
  181. CompactSensorRec_T* scs = NULL;
  182. while(sr != 0)
  183. {
  184. if (sr->Type == FULL_SDR_REC)
  185. {
  186. sfs = (FullSensorRec_T*) sr;
  187. if (sfs->SensorNum == SensorNum) { return sr; }
  188. }
  189. else if (sr->Type == COMPACT_SDR_REC)
  190. {
  191. scs = (CompactSensorRec_T*) sr;
  192. if (scs->SensorNum == SensorNum) { return sr; }
  193. }
  194. /* Get the next record */
  195. sr = SDR_GetNextSDRRec (sr);
  196. }
  197. return NULL;
  198. }
  199. /*-----------------------------------------
  200. * SR_LoadSDRDefaults
  201. * CAUTION !! this function has to be called
  202. * after acquiring a sensor shared memory mutex
  203. *-----------------------------------------*/
  204. extern void
  205. SR_LoadSDRDefaults (SDRRecHdr_T* sr, SensorInfo_T* pSensorInfo)
  206. {
  207. FullSensorRec_T* sfs;
  208. CompactSensorRec_T* scs;
  209. // Populater sensor information for Threshold sensors
  210. if (sr->Type == FULL_SDR_REC)
  211. {
  212. sfs = ( FullSensorRec_T*) sr;
  213. pSensorInfo->SensorOwnerLun = sfs->OwnerLUN; /* Multi-LUN support */
  214. pSensorInfo->SensorNumber = sfs->SensorNum;
  215. pSensorInfo->M_LSB = sfs->M;
  216. pSensorInfo->M_MSB_Tolerance = sfs->M_Tolerance;
  217. pSensorInfo->B_LSB = sfs->B;
  218. pSensorInfo->B_MSB_Accuracy = sfs->B_Accuracy;
  219. pSensorInfo->Accuracy_MSB_Exp = sfs->Accuracy;
  220. pSensorInfo->RExp_BExp = sfs->R_B_Exp;
  221. pSensorInfo->Units1 = sfs->Units1;
  222. pSensorInfo->Units2 = sfs->Units2;
  223. pSensorInfo->Units3 = sfs->Units3;
  224. pSensorInfo->RecordID = sfs->hdr.ID;
  225. pSensorInfo->PosHysteresis = sfs->PositiveHysterisis;
  226. pSensorInfo->NegHysteresis = sfs->NegativeHysterisis;
  227. pSensorInfo->SensorInit = sfs->SensorInit;
  228. pSensorInfo->SettableThreshMask = (sfs->DiscreteReadingMask);
  229. pSensorInfo->SensorCaps = sfs->SensorCaps;
  230. pSensorInfo->SensorTypeCode = sfs->SensorType;
  231. pSensorInfo->OEMField = sfs->OEMField ;
  232. if (pSensorInfo->SensorInit & BIT4)
  233. {
  234. if (pSensorInfo->SettableThreshMask & BIT8)
  235. {
  236. pSensorInfo->LowerNonCritical = sfs->LowerNonCritical;
  237. }
  238. if (pSensorInfo->SettableThreshMask & BIT9)
  239. {
  240. pSensorInfo->LowerCritical = sfs->LowerCritical;
  241. }
  242. if (pSensorInfo->SettableThreshMask & BIT10)
  243. {
  244. pSensorInfo->LowerNonRecoverable = sfs->LowerNonRecoverable;
  245. }
  246. if (pSensorInfo->SettableThreshMask & BIT11)
  247. {
  248. pSensorInfo->UpperNonCritical = sfs->UpperNonCritical;
  249. }
  250. if (pSensorInfo->SettableThreshMask & BIT12)
  251. {
  252. pSensorInfo->UpperCritical = sfs->UpperCritical;
  253. }
  254. if (pSensorInfo->SettableThreshMask & BIT13)
  255. {
  256. pSensorInfo->UpperNonRecoverable = sfs->UpperNonRecoverable;
  257. }
  258. }
  259. pSensorInfo->EventFlags = 0;
  260. pSensorInfo->EventFlags |= sfs->SensorInit & BIT6;
  261. pSensorInfo->EventFlags |= (sfs->SensorInit & BIT5) << 2;
  262. pSensorInfo->EventFlags |= sfs->SensorInit & BIT5;
  263. pSensorInfo->AssertionEventEnablesByte1 = (sfs->AssertionEventMask) & 0xFF;
  264. pSensorInfo->AssertionEventEnablesByte2 = ((sfs->AssertionEventMask) >> 8) & 0xFF;
  265. pSensorInfo->DeassertionEventEnablesByte1= (sfs->DeAssertionEventMask) & 0xFF;
  266. pSensorInfo->DeassertionEventEnablesByte2= ((sfs->DeAssertionEventMask) >> 8) & 0xFF;
  267. pSensorInfo->EventTypeCode = sfs->EventTypeCode;
  268. pSensorInfo->SensorReadType = sfs->EventTypeCode;
  269. pSensorInfo->InternalFlags = 0;
  270. // pSensorInfo->InternalFlags |= BIT0; // Disable internal scanning by default
  271. // Check for a signed sensor
  272. if (0x80 == (sfs->Units1 & 0xC0))
  273. {
  274. pSensorInfo->InternalFlags |= BIT1;
  275. }
  276. }
  277. else if (sr->Type == COMPACT_SDR_REC)
  278. {
  279. scs = ( CompactSensorRec_T*) sr;
  280. pSensorInfo->SensorOwnerLun = scs->OwnerLUN; /* Multi-LUN support */
  281. pSensorInfo->SensorNumber = scs->SensorNum;
  282. pSensorInfo->EventFlags = 0;
  283. pSensorInfo->EventFlags |= scs->SensorInit & BIT6;
  284. pSensorInfo->EventFlags |= (scs->SensorInit & BIT5) << 2;
  285. pSensorInfo->EventFlags |= scs->SensorInit & BIT5;
  286. pSensorInfo->AssertionEventEnablesByte1 = (scs->AssertionEventMask) & 0xFF;
  287. pSensorInfo->AssertionEventEnablesByte2 = ((scs->AssertionEventMask) >> 8) & 0xFF;
  288. pSensorInfo->DeassertionEventEnablesByte1= (scs->DeAssertionEventMask) & 0xFF;
  289. pSensorInfo->DeassertionEventEnablesByte2= ((scs->DeAssertionEventMask) >> 8) & 0xFF;
  290. pSensorInfo->SensorInit = scs->SensorInit;
  291. pSensorInfo->SettableThreshMask = (scs->DiscreteReadingMask);
  292. pSensorInfo->PosHysteresis = scs->PositiveHysteris;
  293. pSensorInfo->NegHysteresis = scs->NegativeHysterisis;
  294. pSensorInfo->EventTypeCode = scs->EventTypeCode;
  295. pSensorInfo->SensorReadType = scs->EventTypeCode;
  296. pSensorInfo->SensorTypeCode = scs->SensorType;
  297. pSensorInfo->SensorCaps = scs->SensorCaps;
  298. pSensorInfo->Units1 = scs->Units1;
  299. pSensorInfo->Units2 = scs->Units2;
  300. pSensorInfo->Units3 = scs->Units3;
  301. pSensorInfo->OEMField = scs->OEMField ;
  302. pSensorInfo->InternalFlags = 0;
  303. // pSensorInfo->InternalFlags |= BIT0; // Disable internal scanning by default
  304. // Check for a signed sensor
  305. if (0x80 == (scs->Units1 & 0xC0))
  306. {
  307. pSensorInfo->InternalFlags |= BIT1;
  308. }
  309. }
  310. }
  311. /*---------------------------------------
  312. * GetDevSDRInfo
  313. *---------------------------------------*/
  314. int
  315. GetDevSDRInfo ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  316. {
  317. GetSDRInfoRes_T* pGetDevSDRInfoRes = (GetSDRInfoRes_T*) pRes;
  318. /* Fill in response data */
  319. pGetDevSDRInfoRes->CompletionCode = CC_NORMAL;
  320. pGetDevSDRInfoRes->NumSensor = g_BMCInfo.SenConfig.ValidSensorCnt;
  321. pGetDevSDRInfoRes->Flags = 0x01; /* BIT7 = 0 (static sensors), BIT0 = 1 (on LUN 0) */
  322. pGetDevSDRInfoRes->TimeStamp = 0;
  323. return sizeof (GetSDRInfoRes_T);
  324. }
  325. /*---------------------------------------
  326. * GetDevSDR
  327. *---------------------------------------*/
  328. int
  329. GetDevSDR ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  330. {
  331. return GetSDR (pReq, ReqLen, pRes);
  332. }
  333. /*---------------------------------------
  334. * GetDevSDR
  335. *---------------------------------------*/
  336. int
  337. ReserveDevSDRRepository ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  338. {
  339. return ReserveSDRRepository (pReq, ReqLen, pRes);
  340. }
  341. /*---------------------------------------
  342. * SetSensorType
  343. *---------------------------------------*/
  344. int
  345. SetSensorType ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  346. {
  347. printf("SetSensorType not implement\r\n");
  348. // //pRes [0] = CC_INV_CMD;
  349. // //return sizeof (*pRes);
  350. // SetSensorTypeReq_T * pSetSensorTypeReq=( SetSensorTypeReq_T *)pReq;
  351. // SetSensorTypeRes_T * pSetSensorTypeRes=( SetSensorTypeRes_T *)pRes;
  352. // SensorSharedMem_T* pSenSharedMem;
  353. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  354. // /* Check for the reserved bytes should b zero */
  355. // if ( 0 != (pSetSensorTypeReq->EventTypeCode & RESERVED_BITS_SETSENSORTYPE ) )
  356. // {
  357. // pSetSensorTypeRes->CompletionCode = CC_INV_DATA_FIELD;
  358. // return sizeof(*pRes);
  359. // }
  360. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo[BMCInst].SensorSharedMemMutex, WAIT_INFINITE);
  361. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  362. // if (!pSenSharedMem->SensorInfo [pSetSensorTypeReq->SensorNum].IsSensorPresent)
  363. // {
  364. // /* Release mutex for Sensor shared memory */
  365. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo[BMCInst].SensorSharedMemMutex);
  366. // /* return sdr record not present completion code */
  367. // pSetSensorTypeRes->CompletionCode = CC_SDR_REC_NOT_PRESENT;
  368. // return sizeof (*pRes);
  369. // }
  370. // pSenSharedMem->SensorInfo[pSetSensorTypeReq->SensorNum].SensorTypeCode=pSetSensorTypeReq->SensorType;
  371. // pSenSharedMem->SensorInfo[pSetSensorTypeReq->SensorNum].EventTypeCode=pSetSensorTypeReq->EventTypeCode;
  372. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo[BMCInst].SensorSharedMemMutex);
  373. // pSetSensorTypeRes->CompletionCode=CC_NORMAL;
  374. // return sizeof(*pSetSensorTypeRes);
  375. return 0;
  376. }
  377. /*---------------------------------------
  378. * GetSensorType
  379. *---------------------------------------*/
  380. int
  381. GetSensorType ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  382. {
  383. //pRes [0] = CC_INV_CMD;
  384. // return sizeof (*pRes);
  385. GetSensorTypeReq_T * pGetSensorTypeReq=( GetSensorTypeReq_T *)pReq;
  386. GetSensorTypeRes_T * pGetSensorTypeRes=( GetSensorTypeRes_T *)pRes;
  387. SensorInfo_T* pSensorInfo = NULL;
  388. pSensorInfo = getSensorInfo(pGetSensorTypeReq->SensorNum);
  389. pGetSensorTypeRes->CompletionCode=CC_NORMAL;
  390. pGetSensorTypeRes->SensorType=pSensorInfo->SensorTypeCode;
  391. pGetSensorTypeRes->EventTypeCode=pSensorInfo->EventTypeCode;
  392. return sizeof(*pGetSensorTypeRes);
  393. }
  394. /*---------------------------------------
  395. * ReArmSensor
  396. *---------------------------------------*/
  397. int
  398. ReArmSensor ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  399. {
  400. printf("ReArmSensor not implement\r\n");
  401. // MsgPkt_T Msg;
  402. // HQueue_T hSMHndlr_Q;
  403. // ReArmSensorReq_T ReArmSensorReq;
  404. // ReArmSensorReq_T* pReArmSensorReq = &ReArmSensorReq;
  405. // ReArmSensorRes_T* pReArmSensorRes = ( ReArmSensorRes_T*) pRes;
  406. // _fmemset (&ReArmSensorReq, 0, sizeof (ReArmSensorReq_T));
  407. // _fmemcpy (&ReArmSensorReq, pReq, ReqLen);
  408. // SensorSharedMem_T* pSenSharedMem;
  409. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  410. // /* if request length is invalid */
  411. // if ((ReqLen < 2) || (ReqLen > sizeof (ReArmSensorReq_T)))
  412. // {
  413. // /* return request invalid length completion code */
  414. // pReArmSensorRes->CompletionCode = CC_REQ_INV_LEN;
  415. // return sizeof (*pRes);
  416. // }
  417. // /* Check for the reserved bytes should b zero */
  418. // if ( 0 != (pReArmSensorReq->ReArmAllEvents & RESERVED_BITS_REARMSENSOR_REARMALLEVENTS ) )
  419. // {
  420. // pReArmSensorRes->CompletionCode = CC_INV_DATA_FIELD;
  421. // return sizeof (*pRes);
  422. // }
  423. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo.SensorSharedMemMutex, WAIT_INFINITE);
  424. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  425. // /* Check for the reserved bits */
  426. // if (pSenSharedMem->SensorInfo [pReArmSensorReq->SensorNum].SensorReadType == THRESHOLD_SENSOR_CLASS)
  427. // {
  428. // if ((pReArmSensorReq->ReArmAssertionEvents2 & RESERVED_BITS_REARMSENSOR_REARMASSEVT2_1) ||
  429. // (pReArmSensorReq->ReArmDeassertionEvents2 & RESERVED_BITS_REARMSENSOR_REARMDEASSEVT2_1))
  430. // {
  431. // pReArmSensorRes->CompletionCode = CC_INV_DATA_FIELD;
  432. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  433. // return sizeof (*pRes);
  434. // }
  435. // }
  436. // else
  437. // {
  438. // if ((pReArmSensorReq->ReArmAssertionEvents2 & RESERVED_BITS_REARMSENSOR_REARMASSEVT2_2) ||
  439. // (pReArmSensorReq->ReArmDeassertionEvents2 & RESERVED_BITS_REARMSENSOR_REARMDEASSEVT2_2))
  440. // {
  441. // pReArmSensorRes->CompletionCode = CC_INV_DATA_FIELD;
  442. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  443. // return sizeof (*pRes);
  444. // }
  445. // }
  446. // if (g_BMCInfo.IpmiConfig.OPMASupport == 1)
  447. // {
  448. // if (pSenSharedMem->GlobalSensorScanningEnable == FALSE)
  449. // {
  450. // pReArmSensorRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  451. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  452. // return sizeof (*pRes);
  453. // }
  454. // }
  455. // if (!pSenSharedMem->SensorInfo [pReArmSensorReq->SensorNum].IsSensorPresent)
  456. // {
  457. // /* return sdr record not present completion code */
  458. // pReArmSensorRes->CompletionCode = CC_SDR_REC_NOT_PRESENT;
  459. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  460. // return sizeof (*pRes);
  461. // }
  462. // Msg.Param = PARAM_REARM_SENSOR;
  463. // Msg.Size = sizeof (ReArmSensorReq_T);
  464. // _fmemcpy(Msg.Data, &ReArmSensorReq, sizeof (ReArmSensorReq_T));
  465. // /* Post to sensormonitor task Thread to rearm this sensor */
  466. // GetQueueHandle(SM_HNDLR_Q,&hSMHndlr_Q,BMCInst);
  467. // if ( -1 != hSMHndlr_Q )
  468. // {
  469. // PostMsg(&Msg, SM_HNDLR_Q,BMCInst);
  470. // /* return normal completion code */
  471. // pReArmSensorRes->CompletionCode = CC_NORMAL;
  472. // }else
  473. // {
  474. // /* return normal completion code */
  475. // pReArmSensorRes->CompletionCode = 0xFF;
  476. // }
  477. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  478. // return (sizeof(ReArmSensorRes_T));
  479. return 1;
  480. }
  481. /*---------------------------------------
  482. * GetSensorEventStatus
  483. *---------------------------------------*/
  484. int
  485. GetSensorEventStatus ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  486. {
  487. GetSensorEventStatusReq_T* pSensorEventStatusReq = ( GetSensorEventStatusReq_T*) pReq;
  488. GetSensorEventStatusRes_T* pSensorEventStatusRes = ( GetSensorEventStatusRes_T*) pRes;
  489. SensorInfo_T* pSensorInfo = getSensorInfo(pSensorEventStatusReq->SensorNum);
  490. pSensorEventStatusRes->CompletionCode = CC_NORMAL;
  491. pSensorEventStatusRes->Flags = (pSensorInfo->EventFlags & 0xe0);
  492. /* Set optional response bytes to zero if event messages are disabled for this sensor */
  493. if (0 == ((pSensorInfo->EventFlags) & BIT7))
  494. {
  495. pSensorEventStatusRes->AssertionEvents1 = 0;
  496. pSensorEventStatusRes->AssertionEvents2 = 0;
  497. pSensorEventStatusRes->DeassertionEvents1 = 0;
  498. pSensorEventStatusRes->DeassertionEvents2 = 0;
  499. return sizeof (GetSensorEventStatusRes_T);
  500. }
  501. if (0 == ((pSensorInfo->SensorCaps) & BIT6))
  502. {
  503. /* Get sensor event status history */
  504. pSensorEventStatusRes->AssertionEvents1 = (pSensorInfo->AssertionHistoryByte1 & pSensorInfo->AssertionEventEnablesByte1);
  505. pSensorEventStatusRes->AssertionEvents2 = (pSensorInfo->AssertionHistoryByte2 & pSensorInfo->AssertionEventEnablesByte2);
  506. pSensorEventStatusRes->DeassertionEvents1 = (pSensorInfo->DeassertionHistoryByte1 & pSensorInfo->DeassertionEventEnablesByte1);
  507. pSensorEventStatusRes->DeassertionEvents2 = (pSensorInfo->DeassertionHistoryByte2 & pSensorInfo->DeassertionEventEnablesByte2);
  508. }
  509. else
  510. {
  511. /* Get present sensor event status */
  512. pSensorEventStatusRes->AssertionEvents1 = (pSensorInfo->AssertionEventOccuredByte1 & pSensorInfo->AssertionEventEnablesByte1);
  513. pSensorEventStatusRes->AssertionEvents2 = (pSensorInfo->AssertionEventOccuredByte2 & pSensorInfo->AssertionEventEnablesByte2);
  514. pSensorEventStatusRes->DeassertionEvents1 = (pSensorInfo->DeassertionEventOccuredByte1 & pSensorInfo->DeassertionEventEnablesByte1);
  515. pSensorEventStatusRes->DeassertionEvents2 =(pSensorInfo->DeassertionEventOccuredByte2 & pSensorInfo->DeassertionEventEnablesByte2);
  516. }
  517. return sizeof (GetSensorEventStatusRes_T);
  518. }
  519. /*---------------------------------------
  520. * SetSensorHysterisis
  521. *---------------------------------------*/
  522. int
  523. SetSensorHysterisis ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  524. {
  525. // SetSensorHysterisisReq_T* pSensorHysReq =
  526. // ( SetSensorHysterisisReq_T*) pReq;
  527. SetSensorHysterisisRes_T* pSensorHysRes =
  528. ( SetSensorHysterisisRes_T*) pRes;
  529. printf("SetSensorHysterisis not implement\r\n");
  530. // SensorSharedMem_T* pSenSharedMem;
  531. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  532. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  533. // if (g_BMCInfo.IpmiConfig.OPMASupport == 1)
  534. // {
  535. // if (pSenSharedMem->GlobalSensorScanningEnable == FALSE)
  536. // {
  537. // pSensorHysRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  538. // return sizeof (*pRes);
  539. // }
  540. // }
  541. // /* Acquire Shared memory */
  542. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo.SensorSharedMemMutex, WAIT_INFINITE);
  543. // if (!pSenSharedMem->SensorInfo [pSensorHysReq->SensorNum].IsSensorPresent)
  544. // {
  545. // /* Release mutex for Sensor shared memory */
  546. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  547. // pSensorHysRes->CompletionCode = CC_SDR_REC_NOT_PRESENT;
  548. // return sizeof (*pRes);
  549. // }
  550. // if (pSenSharedMem->SensorInfo [pSensorHysReq->SensorNum].SensorReadType != THRESHOLD_SENSOR_CLASS)
  551. // {
  552. // /* Release mutex for Sensor shared memory */
  553. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  554. // pSensorHysRes->CompletionCode = CC_ILLEGAL_CMD_FOR_SENSOR_REC;
  555. // return sizeof (*pRes);
  556. // }
  557. // if(BIT5 != (pSenSharedMem->SensorInfo[pSensorHysReq->SensorNum].SensorCaps & (BIT5 | BIT4)))
  558. // {
  559. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  560. // //set operation is not allowed
  561. // *pRes = CC_INV_DATA_FIELD;
  562. // return sizeof(*pRes);
  563. // }
  564. // /* Set the hysterisis values */
  565. // pSenSharedMem->SensorInfo [pSensorHysReq->SensorNum].PosHysteresis = pSensorHysReq->PositiveHysterisis;
  566. // pSenSharedMem->SensorInfo [pSensorHysReq->SensorNum].NegHysteresis = pSensorHysReq->NegativeHysterisis;
  567. // /* Release mutex for Sensor shared memory */
  568. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  569. pSensorHysRes->CompletionCode = CC_NORMAL;
  570. return sizeof (SetSensorHysterisisRes_T);
  571. }
  572. /*---------------------------------------
  573. * GetSensorHysterisis
  574. *---------------------------------------*/
  575. int
  576. GetSensorHysterisis ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  577. {
  578. GetSensorHysterisisReq_T* pSensorHysReq =
  579. ( GetSensorHysterisisReq_T*) pReq;
  580. GetSensorHysterisisRes_T* pSensorHysRes =
  581. ( GetSensorHysterisisRes_T*) pRes;
  582. SensorInfo_T* pSensorInfo = getSensorInfo(pSensorHysReq->SensorNum);
  583. if (pSensorInfo->SensorReadType != THRESHOLD_SENSOR_CLASS)
  584. {
  585. pSensorHysRes->CompletionCode = CC_ILLEGAL_CMD_FOR_SENSOR_REC;
  586. return sizeof (*pRes);
  587. }
  588. if(SENSOR_HYSTERESIS_ACCESS_BITS == (pSensorInfo->SensorCaps & (BIT5 | BIT4)))
  589. {
  590. //set operation is not allowed
  591. *pRes = CC_INV_DATA_FIELD;
  592. return sizeof(*pRes);
  593. }
  594. /* Get the hysterisis values */
  595. pSensorHysRes->PositiveHysterisis = pSensorInfo->PosHysteresis;
  596. pSensorHysRes->NegativeHysterisis = pSensorInfo->NegHysteresis;
  597. pSensorHysRes->CompletionCode = CC_NORMAL;
  598. return sizeof (GetSensorHysterisisRes_T);
  599. }
  600. /*---------------------------------------
  601. * SetSensorThresholds
  602. *---------------------------------------*/
  603. int
  604. SetSensorThresholds ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  605. {
  606. SetSensorThresholdReq_T* pSensorThreshReq =
  607. ( SetSensorThresholdReq_T*) pReq;
  608. SetSensorThresholdRes_T* pSensorThreshRes =
  609. ( SetSensorThresholdRes_T*) pRes;
  610. uint8_t SettableMask=0;
  611. SensorInfo_T* pSensorInfo = getSensorInfo(pSensorThreshReq->SensorNum);
  612. SDRRecHdr_T* pSDRRec = SR_FindSDR(pSensorThreshReq->SensorNum);
  613. FullSensorRec_T* sfs = NULL;
  614. //CompactSensorRec_T* scs = NULL;
  615. if(pSDRRec->Type == FULL_SDR_REC)
  616. {
  617. sfs = (FullSensorRec_T*)pSDRRec;
  618. }
  619. /* Check for the reserved bytes should b zero */
  620. if ( 0 != (pSensorThreshReq->SetFlags & RESERVED_BITS_SETSENSORTHRESHOLDS ) )
  621. {
  622. pSensorThreshRes->CompletionCode = CC_INV_DATA_FIELD;
  623. return sizeof (*pRes);
  624. }
  625. if (pSensorInfo->SensorReadType != THRESHOLD_SENSOR_CLASS)
  626. {
  627. pSensorThreshRes->CompletionCode = CC_ILLEGAL_CMD_FOR_SENSOR_REC;
  628. return sizeof (*pRes);
  629. }
  630. if(BIT3 != (pSensorInfo->SensorCaps & (BIT2 | BIT3)))
  631. {
  632. //set operation is not allowed
  633. *pRes = CC_INV_DATA_FIELD;
  634. return sizeof(*pRes);
  635. }
  636. pSensorThreshRes->CompletionCode = CC_NORMAL;
  637. SettableMask=(uint8_t)(pSensorInfo->SettableThreshMask >> 8);
  638. /* Set the threshold values */
  639. //if (pSenSharedMem->SensorInfo [pSensorThreshReq->SensorNum].SensorInit & BIT5)
  640. if ( (pSensorInfo->SensorInit & BIT4 ) && (SettableMask | pSensorThreshReq->SetFlags ) == SettableMask) //<<Modified to support "set sensor enable>>
  641. {
  642. if (pSensorThreshReq->SetFlags & LWR_CRIT)
  643. {
  644. pSensorInfo->LowerCritical = pSensorThreshReq->LowerCritical;
  645. if(sfs != NULL) {sfs->LowerCritical = pSensorThreshReq->LowerCritical;}
  646. }
  647. if (pSensorThreshReq->SetFlags & LWR_NON_CRIT)
  648. {
  649. pSensorInfo->LowerNonCritical = pSensorThreshReq->LowerNonCritical;
  650. if(sfs != NULL) {sfs->LowerNonCritical = pSensorThreshReq->LowerNonCritical;}
  651. }
  652. if (pSensorThreshReq->SetFlags & LWR_NON_REC)
  653. {
  654. pSensorInfo->LowerNonRecoverable = pSensorThreshReq->LowerNonRecoverable;
  655. if(sfs != NULL) {sfs->LowerNonRecoverable = pSensorThreshReq->LowerNonRecoverable;}
  656. }
  657. if (pSensorThreshReq->SetFlags & UPR_CRIT)
  658. {
  659. pSensorInfo->UpperCritical = pSensorThreshReq->UpperCritical;
  660. if(sfs != NULL) {sfs->UpperCritical = pSensorThreshReq->UpperCritical;}
  661. }
  662. if (pSensorThreshReq->SetFlags & UPR_NON_CRIT)
  663. {
  664. pSensorInfo->UpperNonCritical = pSensorThreshReq->UpperNonCritical;
  665. if(sfs != NULL) {sfs->UpperNonCritical = pSensorThreshReq->UpperNonCritical;}
  666. }
  667. if (pSensorThreshReq->SetFlags & UPR_NON_REC)
  668. {
  669. pSensorInfo->UpperNonRecoverable = pSensorThreshReq->UpperNonRecoverable;
  670. if(sfs != NULL) {sfs->UpperNonRecoverable = pSensorThreshReq->UpperNonRecoverable;}
  671. }
  672. if(g_BMCInfo.IpmiConfig.RearmSetSensorThreshold == 1)
  673. {
  674. /* Since Changes in Threshold .We have to monitor the sensor again .*/
  675. /* Already the Sensor reached the particular state . so we have to reset for generate the event according to the new Event mask */
  676. if ( 0 ==(pSensorInfo->SensorCaps & BIT6))
  677. {
  678. /* Manual ReARM Sensor */
  679. pSensorInfo->AssertionHistoryByte1=0;
  680. pSensorInfo->AssertionHistoryByte2=0;
  681. pSensorInfo->DeassertionHistoryByte1=0;
  682. pSensorInfo->DeassertionHistoryByte2=0;
  683. pSensorInfo->EventLevel=SENSOR_STATUS_NORMAL;
  684. pSensorInfo->HealthLevel= SENSOR_STATUS_NORMAL;
  685. }else
  686. {
  687. /* Auto ReARM Sensor */
  688. pSensorInfo->EventLevel=SENSOR_STATUS_NORMAL;
  689. pSensorInfo->HealthLevel = SENSOR_STATUS_NORMAL;
  690. pSensorInfo->AssertionEventOccuredByte1 = 0;
  691. pSensorInfo->AssertionEventOccuredByte2 = 0;
  692. pSensorInfo->DeassertionEventOccuredByte1 = 0;
  693. pSensorInfo->DeassertionEventOccuredByte2 = 0;
  694. }
  695. }
  696. pSensorThreshRes->CompletionCode = CC_NORMAL;
  697. UpdateFlash();
  698. }
  699. else
  700. {
  701. pSensorThreshRes->CompletionCode = CC_ILLEGAL_CMD_FOR_SENSOR_REC;
  702. }
  703. return sizeof (SetSensorThresholdRes_T);
  704. }
  705. /*---------------------------------------
  706. * GetSensorThresholds
  707. *---------------------------------------*/
  708. int
  709. GetSensorThresholds ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  710. {
  711. GetSensorThresholdReq_T* pSensorThreshReq =
  712. ( GetSensorThresholdReq_T*) pReq;
  713. GetSensorThresholdRes_T* pSensorThreshRes =
  714. ( GetSensorThresholdRes_T*) pRes;
  715. SensorInfo_T* pSensorInfo = getSensorInfo(pSensorThreshReq->SensorNum);
  716. if (pSensorInfo->SensorReadType != THRESHOLD_SENSOR_CLASS)
  717. {
  718. pSensorThreshRes->CompletionCode = CC_ILLEGAL_CMD_FOR_SENSOR_REC;
  719. return sizeof (*pRes);
  720. }
  721. memset (pSensorThreshRes, 0, sizeof (GetSensorThresholdRes_T));
  722. if(SENSOR_THRESOLD_ACCESS_BITS != (pSensorInfo->SensorCaps & (BIT2 | BIT3)))
  723. {
  724. pSensorThreshRes->GetFlags = pSensorInfo->SettableThreshMask & 0xFF;
  725. /* Get the Threshold values according to readable threshold flag */
  726. if( pSensorThreshRes->GetFlags & BIT0 )
  727. pSensorThreshRes->LowerNonCritical = pSensorInfo->LowerNonCritical;
  728. if( pSensorThreshRes->GetFlags & BIT1 )
  729. pSensorThreshRes->LowerCritical = pSensorInfo->LowerCritical;
  730. if( pSensorThreshRes->GetFlags & BIT2 )
  731. pSensorThreshRes->LowerNonRecoverable = pSensorInfo->LowerNonRecoverable;
  732. if( pSensorThreshRes->GetFlags & BIT3 )
  733. pSensorThreshRes->UpperNonCritical = pSensorInfo->UpperNonCritical;
  734. if( pSensorThreshRes->GetFlags & BIT4 )
  735. pSensorThreshRes->UpperCritical = pSensorInfo->UpperCritical;
  736. if( pSensorThreshRes->GetFlags & BIT5 )
  737. pSensorThreshRes->UpperNonRecoverable = pSensorInfo->UpperNonRecoverable;
  738. }
  739. pSensorThreshRes->CompletionCode = CC_NORMAL;
  740. return sizeof (GetSensorThresholdRes_T);
  741. }
  742. /*---------------------------------------
  743. * GetSensorReadingFactors
  744. *---------------------------------------*/
  745. int
  746. GetSensorReadingFactors ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  747. {
  748. GetSensorReadingFactorReq_T* pSensorFactorsReq =
  749. ( GetSensorReadingFactorReq_T*) pReq;
  750. GetSensorReadingFactorRes_T* pSensorFactorsRes =
  751. ( GetSensorReadingFactorRes_T*) pRes;
  752. SensorInfo_T* pSensorInfo = getSensorInfo(pSensorFactorsReq->SensorNum);
  753. memcpy (&(pSensorFactorsRes->M_LSB), &(pSensorInfo->M_LSB),
  754. sizeof (GetSensorReadingFactorRes_T) - (2 * sizeof (uint8_t)));
  755. pSensorFactorsRes->CompletionCode = CC_NORMAL;
  756. return sizeof (GetSensorReadingFactorRes_T);
  757. }
  758. /*---------------------------------------
  759. * SetSensorEventEnable
  760. *---------------------------------------*/
  761. int
  762. SetSensorEventEnable ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  763. {
  764. // SensorInfo_T* pSensorInfo;
  765. // uint8_t LocalReq [6];
  766. // SetSensorEventEnableReq_T* pSensorEvtEnReq;
  767. // SetSensorEventEnableRes_T* pSensorEvtEnRes =
  768. // ( SetSensorEventEnableRes_T*) pRes;
  769. printf("SetSensorEventEnable not implement\r\n");
  770. // uint16_t AssertMask, DeassertMask;
  771. // uint16_t ValidMask = htoipmi_u16(0x0FFF);
  772. // SensorSharedMem_T* pSenSharedMem;
  773. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  774. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  775. // uint16_t LUNSensorNum;
  776. // uint16_t *OwnerLUN = 0;
  777. // if (g_BMCInfo.IpmiConfig.OPMASupport == 1)
  778. // {
  779. // if (pSenSharedMem->GlobalSensorScanningEnable == FALSE)
  780. // {
  781. // pSensorEvtEnRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  782. // return sizeof (*pRes);
  783. // }
  784. // }
  785. // AssertMask = DeassertMask = 0;
  786. // memset (LocalReq, 0, sizeof (LocalReq));
  787. // memcpy (LocalReq, pReq, ReqLen);
  788. // pSensorEvtEnReq = ( SetSensorEventEnableReq_T*)LocalReq;
  789. // if(g_corefeatures.more_than_256_sensors == ENABLED)
  790. // {
  791. // OS_THREAD_TLS_GET(g_tls.OwnerLUN,OwnerLUN);
  792. // LUNSensorNum = ((*OwnerLUN & VALID_LUN) << 8 | pSensorEvtEnReq->SensorNum);
  793. // }
  794. // else
  795. // {
  796. // LUNSensorNum = pSensorEvtEnReq->SensorNum;
  797. // }
  798. // /* Atleast two bytes are expected remaining bytes (3,4,5,6) are optional */
  799. // if ((ReqLen < sizeof(uint16_t)) || (ReqLen > sizeof (SetSensorEventEnableReq_T)))
  800. // {
  801. // pSensorEvtEnRes->CompletionCode = CC_REQ_INV_LEN;
  802. // return sizeof (*pRes);
  803. // }
  804. // /* Check for the reserved bytes should b zero */
  805. // if ( 0 != (pSensorEvtEnReq->Flags & RESERVED_BITS_SETSENEVTEN_FLAGS ) )
  806. // {
  807. // pSensorEvtEnRes->CompletionCode = CC_INV_DATA_FIELD;
  808. // return sizeof (*pRes);
  809. // }
  810. // if (ReqLen > sizeof(uint16_t))
  811. // {
  812. // /* Check for the reserved bits */
  813. // if (pSenSharedMem->SensorInfo [LUNSensorNum].SensorReadType == THRESHOLD_SENSOR_CLASS)
  814. // {
  815. // if ((pSensorEvtEnReq->AssertionMask & ~ValidMask) ||
  816. // (pSensorEvtEnReq->DeAssertionMask & ~ValidMask))
  817. // {
  818. // pSensorEvtEnRes->CompletionCode = CC_INV_DATA_FIELD;
  819. // return sizeof (*pRes);
  820. // }
  821. // }
  822. // else
  823. // {
  824. // if ((pSensorEvtEnReq->AssertionMask & RESERVED_BITS_SETSENEVTEN_ASSERTIONMASK) ||
  825. // (pSensorEvtEnReq->DeAssertionMask & RESERVED_BITS_SETSENEVTEN_DEASSERTIONMASK))
  826. // {
  827. // pSensorEvtEnRes->CompletionCode = CC_INV_DATA_FIELD;
  828. // return sizeof (*pRes);
  829. // }
  830. // }
  831. // }
  832. // /* Get the sensor Info for the sensor */
  833. // if(g_corefeatures.more_than_256_sensors == ENABLED)
  834. // {
  835. // pSensorInfo = GetSensorInfo (pSensorEvtEnReq->SensorNum, *OwnerLUN, BMCInst);
  836. // }
  837. // else
  838. // {
  839. // pSensorInfo = GetSensorInfo (pSensorEvtEnReq->SensorNum, 0x0, BMCInst);
  840. // }
  841. // if (NULL == pSensorInfo)
  842. // {
  843. // pSensorEvtEnRes->CompletionCode = CC_SDR_REC_NOT_PRESENT;
  844. // return sizeof (*pRes);
  845. // }
  846. // // If not threshold, adjust mask
  847. // if (pSensorInfo->EventTypeCode != 0x01)
  848. // {
  849. // ValidMask = htoipmi_u16(0x7FFF);
  850. // }
  851. // /* Acquire Shared memory */
  852. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo.SensorSharedMemMutex, WAIT_INFINITE);
  853. // if (!pSensorInfo->IsSensorPresent)
  854. // {
  855. // /* Release mutex for Sensor shared memory */
  856. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  857. // pSensorEvtEnRes->CompletionCode = CC_SDR_REC_NOT_PRESENT;
  858. // return sizeof (*pRes);
  859. // }
  860. // /* Disable Events and scanning based on the flags */
  861. // if (0 == (pSensorEvtEnReq->Flags & EVENT_MSG_MASK))
  862. // {
  863. // /* DisableAllEventSensors () */
  864. // }
  865. // if ((0 == (pSensorEvtEnReq->Flags & SCAN_MASK)) && (SCAN_MASK == (pSensorInfo->EventFlags & SCAN_MASK)))
  866. // {
  867. // // Check sensor accepts the ‘enable/disable scanning’
  868. // if(0 == (pSensorInfo->SensorInit & BIT6))
  869. // {
  870. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  871. // pSensorEvtEnRes->CompletionCode = CC_INV_DATA_FIELD;
  872. // return sizeof (*pRes);
  873. // }
  874. // pSensorInfo->EventFlags |= BIT5; ///* Bit 5 - Unable to read */
  875. // }
  876. // else if((SCAN_MASK == (pSensorEvtEnReq->Flags & SCAN_MASK)) && (0 == (pSensorInfo->EventFlags & SCAN_MASK)))
  877. // {
  878. // // Check sensor accepts the ‘enable/disable scanning’
  879. // if(0 == (pSensorInfo->SensorInit & BIT6))
  880. // {
  881. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  882. // pSensorEvtEnRes->CompletionCode = CC_INV_DATA_FIELD;
  883. // return sizeof (*pRes);
  884. // }
  885. // pSensorInfo->EventFlags &= ~BIT5; ///* Bit 5 - Unable to read */
  886. // }
  887. // pSensorInfo->EventFlags &= ~(EVENT_MSG_MASK | SCAN_MASK);
  888. // pSensorInfo->EventFlags |= (pSensorEvtEnReq->Flags & (EVENT_MSG_MASK | SCAN_MASK));
  889. // AssertMask =
  890. // htoipmi_u16(((pSenSharedMem->SensorInfo [LUNSensorNum].AssertionEventEnablesByte2 << 8) |
  891. // (pSenSharedMem->SensorInfo [LUNSensorNum].AssertionEventEnablesByte1)) & ValidMask);
  892. // DeassertMask =
  893. // htoipmi_u16(((pSenSharedMem->SensorInfo [LUNSensorNum].DeassertionEventEnablesByte2 << 8) |
  894. // (pSenSharedMem->SensorInfo [LUNSensorNum].DeassertionEventEnablesByte1)) & ValidMask);
  895. // /* Enable disable assertion based on the flag */
  896. // if(ENABLE_DISABLE_EVENT_MASK == (pSensorEvtEnReq->Flags & ENABLE_DISABLE_EVENT_MASK))
  897. // {
  898. // // Flags [5:4] - 11b Reserved.
  899. // /* Release mutex for Sensor shared memory */
  900. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  901. // pSensorEvtEnRes->CompletionCode = CC_INV_DATA_FIELD;
  902. // return sizeof (*pRes);
  903. // }
  904. // else if (ENABLE_SELECTED_EVENT_MSG == (pSensorEvtEnReq->Flags & ENABLE_DISABLE_EVENT_MASK))
  905. // {
  906. // AssertMask |= ipmitoh_u16(pSensorEvtEnReq->AssertionMask);
  907. // DeassertMask |= ipmitoh_u16(pSensorEvtEnReq->DeAssertionMask);
  908. // }
  909. // else if (DISABLE_SELECTED_EVENT_MSG == (pSensorEvtEnReq->Flags & ENABLE_DISABLE_EVENT_MASK))
  910. // {
  911. // AssertMask &= ~ipmitoh_u16(pSensorEvtEnReq->AssertionMask);
  912. // DeassertMask &= ~ipmitoh_u16(pSensorEvtEnReq->DeAssertionMask);
  913. // }
  914. // //For Threshold class sensors upper word bits are reserved
  915. // if(pSensorInfo->EventTypeCode == THRESHOLD_SENSOR_CLASS)
  916. // {
  917. // pSensorInfo->AssertionEventEnablesByte2 &= 0xF0;
  918. // pSensorInfo->AssertionEventEnablesByte2 |= (AssertMask >> 8);
  919. // }
  920. // else
  921. // {
  922. // pSensorInfo->AssertionEventEnablesByte2 = (AssertMask >> 8);
  923. // }
  924. // pSensorInfo->AssertionEventEnablesByte1 = (AssertMask) & 0xFF;
  925. // //For Threshold class sensors upper word bits are reserved
  926. // if(pSensorInfo->EventTypeCode == THRESHOLD_SENSOR_CLASS)
  927. // {
  928. // pSensorInfo->DeassertionEventEnablesByte2 &= 0xF0;
  929. // pSensorInfo->DeassertionEventEnablesByte2 |= (DeassertMask >> 8);
  930. // }
  931. // else
  932. // {
  933. // pSensorInfo->DeassertionEventEnablesByte2 = (DeassertMask >> 8);
  934. // }
  935. // pSensorInfo->DeassertionEventEnablesByte1 = (DeassertMask);
  936. // // For threshold sensors, reset the threshold state machine for the sensor
  937. // // in order to pickup any newly enabled events.
  938. // if(pSensorInfo->EventTypeCode == THRESHOLD_SENSOR_CLASS)
  939. // {
  940. // pSensorInfo->EventLevel=SENSOR_STATUS_NORMAL;
  941. // pSensorInfo->HealthLevel = SENSOR_STATUS_NORMAL;
  942. // }
  943. // pSensorEvtEnRes->CompletionCode = CC_NORMAL;
  944. // /* Release mutex for Sensor shared memory */
  945. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  946. return sizeof (SetSensorEventEnableRes_T);
  947. }
  948. /*---------------------------------------
  949. * GetSensorEventEnable
  950. *---------------------------------------*/
  951. int
  952. GetSensorEventEnable ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  953. {
  954. GetSensorEventEnableReq_T* pSensorEvtEnReq =
  955. ( GetSensorEventEnableReq_T*) pReq;
  956. GetSensorEventEnableRes_T* pSensorEvtEnRes =
  957. ( GetSensorEventEnableRes_T*) pRes;
  958. SensorInfo_T* pSensorInfo = getSensorInfo(pSensorEvtEnReq->SensorNum);
  959. uint16_t ValidMask = (0x0FFF);
  960. if (pSensorInfo->EventTypeCode != 0x01)
  961. {
  962. ValidMask = (0x7FFF);
  963. }
  964. /* Get the assertion enables */
  965. pSensorEvtEnRes->AssertionMask =
  966. (((pSensorInfo->AssertionEventEnablesByte2 << 8) | (pSensorInfo->AssertionEventEnablesByte1)) & ValidMask);
  967. /* Get the deassertion enables */
  968. pSensorEvtEnRes->DeAssertionMask =
  969. (((pSensorInfo->DeassertionEventEnablesByte2 << 8) | (pSensorInfo->DeassertionEventEnablesByte1)) & ValidMask);
  970. /* Set the flags */
  971. pSensorEvtEnRes->Flags = (pSensorInfo->EventFlags & 0xc0);
  972. pSensorEvtEnRes->CompletionCode = CC_NORMAL;
  973. return sizeof (GetSensorEventEnableRes_T);
  974. }
  975. /**
  976. * @fn CheckForEntityPresence
  977. * @brief This function checks for the entity presence bit
  978. * or the entity presence sensor.
  979. * @param[in] SensorNum - Sensor number for reading.
  980. * @param[in] EventTypeCode - Event type code of the sdr.
  981. * @param[in] SensorType - Sensor type of the sdr.
  982. * @retval ENTITY_FOUND, if present,
  983. * ENTITY_NOT_FOUND, if not present,
  984. * NOT_FOUND_SCAN_DISABLED, if not able to find,
  985. * NOT_FOUND_SCAN_ENABLED, if Scanning bit enabled but failed.
  986. */
  987. static int
  988. CheckForEntityPresence (uint8_t SensorNum, uint8_t OwnerLUN, uint8_t EventTypeCode, uint8_t SensorType)
  989. {
  990. int RetVal = NOT_FOUND_SCAN_ENABLED;
  991. SensorInfo_T* pSensorInfo;
  992. int i;
  993. pSensorInfo = getSensorInfo(SensorNum);
  994. if( BIT0 == (BIT0 & pSensorInfo->SensorInit) )
  995. {
  996. // If Event/Reading type code is 0x08 then look for
  997. // reading DEVICE_PRESENT to state the Entity Presence
  998. if( GENERIC_EVENT_TYPE_DEV_PRESENCE == EventTypeCode )
  999. {
  1000. if( DEVICE_PRESENT == pSensorInfo->SensorReading )
  1001. {
  1002. RetVal = ENTITY_FOUND;
  1003. }
  1004. else
  1005. {
  1006. RetVal = ENTITY_NOT_FOUND;
  1007. }
  1008. }
  1009. // If Event/Reading type code is 0x09 then look for
  1010. // reading DEVICE_ENABLED to state the Entity Enabled
  1011. else if( GENERIC_EVENT_TYPE_DEV_AVAILABLE == EventTypeCode )
  1012. {
  1013. if( DEVICE_ENABLED == pSensorInfo->SensorReading )
  1014. {
  1015. RetVal = ENTITY_FOUND;
  1016. }
  1017. else
  1018. {
  1019. RetVal = ENTITY_NOT_FOUND;
  1020. }
  1021. }
  1022. // If Event/Reading Type code is 0x6f then look for the
  1023. // special sensors like Processor, Memory etc.,
  1024. else if ( EVENT_TYPE_SENSOR_SPECIFIC == EventTypeCode )
  1025. {
  1026. for(i = 0; i < SENSOR_PRESENCE_COUNT; i++)
  1027. {
  1028. if( SensorType == sensor_presence[i][0] )
  1029. {
  1030. if( pSensorInfo->SensorReading == sensor_presence[i][1] )
  1031. RetVal = ENTITY_FOUND;
  1032. else
  1033. RetVal = ENTITY_NOT_FOUND;
  1034. }
  1035. }
  1036. }
  1037. return RetVal;
  1038. }
  1039. return NOT_FOUND_SCAN_DISABLED;
  1040. }
  1041. /**
  1042. * @fn IsSensorPresence
  1043. * @brief Check the presence bit for the entity or checks with
  1044. * entity presence sensor to identify Entity presence
  1045. * @param[in] EntityID - Entity id of the sensor.
  1046. * @param[in] EntityIns - Entity instance of the sensor.
  1047. * @param[in] SensorNum - Sensor number.
  1048. * @retval 1, if present
  1049. * 0, if not present
  1050. * -1, if not able to find.
  1051. */
  1052. static int
  1053. IsSensorPresence (uint8_t EntityID, uint8_t EntityIns, uint8_t SensorNum, uint8_t OwnerLUN)
  1054. {
  1055. SDRRecHdr_T* sr = NULL;
  1056. CommonSensorRec_T* scs = NULL;
  1057. int RetVal, tmpRet = -1;
  1058. sr = SDR_GetFirstSDRRec ();
  1059. while (0 != sr)
  1060. {
  1061. // Populate sensor information for Threshold sensors
  1062. if (FULL_SDR_REC == sr->Type || COMPACT_SDR_REC == sr->Type)
  1063. {
  1064. /* Populate sensor information for full or Compact Record */
  1065. scs = ( CommonSensorRec_T*) sr;
  1066. // Check for EntityId and EntityIns
  1067. if((EntityID == scs->EntityID) && (EntityIns == scs->EntityIns) &&
  1068. ((SensorNum != scs->SensorNum) || (OwnerLUN != scs->OwnerLUN)) )
  1069. {
  1070. RetVal = CheckForEntityPresence (scs->SensorNum, scs->OwnerLUN, scs->EventTypeCode,
  1071. scs->SensorType);
  1072. if( NOT_FOUND_SCAN_DISABLED != RetVal && NOT_FOUND_SCAN_ENABLED != RetVal)
  1073. {
  1074. return RetVal;
  1075. }
  1076. else if( NOT_FOUND_SCAN_ENABLED == RetVal)
  1077. {
  1078. // An Entity is present if there is at least one active
  1079. // sensor for the Entity (and there is no explicit sensor saying
  1080. // the Entity is 'absent').
  1081. // A sensor is 'active' if scanning is enabled.
  1082. // We can return this value only after searching all the sensors.
  1083. tmpRet = 1;
  1084. }
  1085. }
  1086. }
  1087. /* Get the next record */
  1088. sr = SDR_GetNextSDRRec (sr);
  1089. }
  1090. return tmpRet;
  1091. }
  1092. /**
  1093. * @fn IsEntityAssociationPresence
  1094. * @brief Check the EntityID and Entity instance to see if the entity is
  1095. * a container entity in an entity-association. If so, check to
  1096. * see if any of the contained entities are present, if so, assume
  1097. * the container entity exists.
  1098. * @param[in] EntityID - Entity id of the sensor.
  1099. * @param[in] EntityIns - Entity instance of the sensor.
  1100. * @retval 1, if present
  1101. * 0, if not present
  1102. * -1, if not able to find.
  1103. */
  1104. static int
  1105. IsEntityAssociationPresence (uint8_t EntityID, uint8_t EntityIns)
  1106. {
  1107. //TODO
  1108. return -1;
  1109. }
  1110. /**
  1111. * @fn IsFRUPresence
  1112. * @brief Check the entity to see if FRU device is present.
  1113. * @param[in] EntityID - Entity id of the sensor.
  1114. * @param[in] EntityIns - Entity instance of the sensor.
  1115. * @retval 1, if present
  1116. * 0, if not present
  1117. * -1, if not able to find.
  1118. */
  1119. static int
  1120. IsFRUPresence (uint8_t EntityID, uint8_t EntityIns)
  1121. {
  1122. printf("IsFRUPresence not implement\r\n");
  1123. // SDRRecHdr_T* sr = NULL;
  1124. // FRUDevLocatorRec_T* frudl;
  1125. // FRUReadReq_T FRUReadReq;
  1126. // uint8_t FRUReadRes[64];
  1127. // sr = SDR_GetFirstSDRRec (BMCInst);
  1128. // while (0 != sr)
  1129. // {
  1130. // // Check for FRU Device locator SDR Record
  1131. // if (sr->Type == FRU_DEVICE_LOCATOR_SDR_REC)
  1132. // {
  1133. // frudl = ( FRUDevLocatorRec_T*) sr;
  1134. // frudl->EntityID, frudl->EntityIns);
  1135. // // If EntityID and EntityIns are equal try to read the fru data.
  1136. // if(frudl->EntityID == EntityID &&
  1137. // frudl->EntityIns == EntityIns)
  1138. // {
  1139. // FRUReadReq.FRUDeviceID=frudl->FRUIDSlaveAddr;
  1140. // FRUReadReq.Offset=0x0;
  1141. // FRUReadReq.CountToRead=sizeof(FRUCommonHeader_T);
  1142. // ReadFRUData((uint8_t *)&FRUReadReq, sizeof(FRUReadReq_T), FRUReadRes);
  1143. // if (((FRUReadRes_T *)FRUReadRes)->CompletionCode == FRU_ACCESSIBLE)
  1144. // {
  1145. // return 1;
  1146. // }
  1147. // else
  1148. // {
  1149. // return 0;
  1150. // }
  1151. // }
  1152. // }
  1153. // sr = SDR_GetNextSDRRec (sr);
  1154. // }
  1155. return -1;
  1156. }
  1157. /**
  1158. * @fn InitSensorScanningBit
  1159. * @brief Initializes all the sensor's Scanning bit with respect
  1160. * to the presence of the entity
  1161. * @retval 0.
  1162. */
  1163. int InitSensorScanningBit()
  1164. {
  1165. SDRRecHdr_T* sr = NULL;
  1166. CommonSensorRec_T* scs = NULL;
  1167. int RetVal;
  1168. SensorInfo_T* pSensorInfo = NULL;
  1169. uint16_t LUNSensorNum;
  1170. sr = SDR_GetFirstSDRRec ();
  1171. while (0 != sr)
  1172. {
  1173. // Populater sensor information for Threshold sensors
  1174. if (FULL_SDR_REC == sr->Type || COMPACT_SDR_REC == sr->Type)
  1175. {
  1176. scs = ( CommonSensorRec_T*) sr;
  1177. RetVal = 1;
  1178. if( BIT7 == (BIT7 & scs->SensorCaps) )
  1179. {
  1180. /* As per IPMI Spec Section 40.2
  1181. * Entity presence can be detected if any one of the following point is
  1182. * Satisfied,
  1183. * 1. If there is an active sensor that includes a presence bit,
  1184. * or the entity has an active Entity Presence sensor,
  1185. * use the sensor to determine the presence of the entity.
  1186. * 2. Check the SDRs to see if the entity is a container entity
  1187. * in an entity-association. If so, check to see if any of the
  1188. * contained entities are present, if so, assume the container
  1189. * entity exists. Note that this may need to be iterative.
  1190. * 3. The entity is present is there is a FRU device for the
  1191. * entity, and the FRU device is present.
  1192. */
  1193. RetVal = IsSensorPresence(scs->EntityID, scs->EntityIns, scs->SensorNum, scs->OwnerLUN);
  1194. if( -1 == RetVal )
  1195. {
  1196. RetVal = IsEntityAssociationPresence(scs->EntityID, scs->EntityIns);
  1197. if( -1 == RetVal )
  1198. {
  1199. RetVal = IsFRUPresence(scs->EntityID, scs->EntityIns);
  1200. }
  1201. }
  1202. }
  1203. LUNSensorNum = (scs->SensorNum);
  1204. /*
  1205. * [7] - 0b = All Event Messages disabled from this sensor
  1206. * [6] - 0b = sensor scanning disabled
  1207. * [5] - 1b = reading/state unavailable
  1208. */
  1209. if(1 == RetVal)
  1210. {
  1211. pSensorInfo = getSensorInfo(LUNSensorNum);
  1212. if((BIT0 | BIT1) == (pSensorInfo->SensorInit & (BIT0 | BIT1)))
  1213. {
  1214. /* Enabling Sensor Scanning and Event Messages*/
  1215. pSensorInfo->EventFlags = EVENT_AND_SCANNING_ENABLE;
  1216. }
  1217. else if(BIT1 == (pSensorInfo->SensorInit & BIT1))
  1218. {
  1219. /* Enabling Event Messages */
  1220. pSensorInfo->EventFlags = EVENT_MSG_MASK;
  1221. }
  1222. else if(BIT0 == (pSensorInfo->SensorInit & BIT0))
  1223. {
  1224. /*Enabling Scanning*/
  1225. pSensorInfo->EventFlags = SCAN_MASK;
  1226. }
  1227. if(0 == (pSensorInfo->SensorInit & BIT0))
  1228. {
  1229. /* Reading Unavailable */
  1230. pSensorInfo->EventFlags |= READING_UNAVAILABLE;
  1231. }
  1232. }
  1233. else
  1234. {
  1235. pSensorInfo->EventFlags = READING_UNAVAILABLE;
  1236. if(BIT1 == (pSensorInfo->SensorInit & BIT1))
  1237. {
  1238. /* Enabling Event Messages */
  1239. pSensorInfo->EventFlags |= EVENT_MSG_MASK;
  1240. }
  1241. }
  1242. }
  1243. /* Get the next record */
  1244. sr = SDR_GetNextSDRRec (sr);
  1245. }
  1246. printf("Leaving : %s with 0\n", __func__);
  1247. return 0;
  1248. }
  1249. /* Compare two sensor values.
  1250. * Returns -1 if val1 < val2
  1251. * Returns 0 if val1 == val2
  1252. * Returns 1 if val1 > val2
  1253. */
  1254. int
  1255. CompareValues(uint8_t isSigned, uint8_t val1, uint8_t val2)
  1256. {
  1257. int retval = 0; // default to equal
  1258. // Signed comparison
  1259. int8_t sval1, sval2;
  1260. /* Do comparison based on isSigned flag */
  1261. if (FALSE == isSigned)
  1262. {
  1263. // Unsigned comparison
  1264. if (val1 < val2)
  1265. {
  1266. retval = -1;
  1267. }
  1268. else if (val1 > val2)
  1269. {
  1270. retval = 1;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. sval1 = (int8_t)val1;
  1276. sval2 = (int8_t)val2;
  1277. if (sval1 < sval2)
  1278. {
  1279. retval = -1;
  1280. }
  1281. else if (sval1 > sval2)
  1282. {
  1283. retval = 1;
  1284. }
  1285. }
  1286. return retval;
  1287. }
  1288. /*-----------------------------------------
  1289. * GetSensorReading
  1290. *-----------------------------------------*/
  1291. int
  1292. GetSensorReading ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1293. {
  1294. GetSensorReadingReq_T* pSensorReadReq =
  1295. ( GetSensorReadingReq_T*) pReq;
  1296. GetSensorReadingRes_T* pSensorReadRes =
  1297. ( GetSensorReadingRes_T*) pRes;
  1298. uint16_t SensorReading;
  1299. uint8_t SensorIsSigned = FALSE;
  1300. SensorInfo_T * pSensorInfo = NULL;
  1301. pSensorInfo = getSensorInfo(pSensorReadReq->SensorNum);
  1302. //printf("---> pSensorInfo %p, reading: %#x\n", pSensorInfo, pSensorInfo->SensorReading);
  1303. pSensorReadRes->Flags = pSensorInfo->EventFlags & 0xe0;
  1304. if (0 != (pSensorInfo->EventFlags & BIT5))
  1305. {
  1306. //printf("---> log 1\n");
  1307. pSensorReadRes->SensorReading = 0;
  1308. pSensorReadRes->CompletionCode = CC_NORMAL;
  1309. pSensorReadRes->ComparisonStatus = (((uint8_t) (pSensorReadRes->SensorReading & 0x00FF)) & ((uint8_t) (pSensorInfo->SettableThreshMask & 0x00FF)) );
  1310. pSensorReadRes->OptionalStatus = (((uint8_t) (pSensorReadRes->SensorReading >> 8)) & ((uint8_t)(pSensorInfo->SettableThreshMask >> 8)) );
  1311. // For Discrete sensor, [7] - reserved. Returned as 1b. Ignore on read.
  1312. pSensorReadRes->OptionalStatus |= 0x80;
  1313. return sizeof (GetSensorReadingRes_T);
  1314. }
  1315. pSensorReadRes->CompletionCode = CC_NORMAL;
  1316. SensorReading = pSensorInfo->SensorReading;
  1317. pSensorReadRes->SensorReading = 0;
  1318. SensorIsSigned = (0 != (pSensorInfo->Units1 & 0xC0)) ? TRUE : FALSE;
  1319. if (THRESHOLD_SENSOR_CLASS == pSensorInfo->EventTypeCode)
  1320. {
  1321. //printf("---> log2\n");
  1322. pSensorReadRes->SensorReading = (SensorReading & 0x00FF); //notice
  1323. pSensorReadRes->ComparisonStatus = 0x00;
  1324. if((pSensorInfo->DeassertionEventEnablesByte2 & BIT6) == BIT6 )
  1325. {
  1326. if (CompareValues(SensorIsSigned, pSensorReadRes->SensorReading,
  1327. pSensorInfo->UpperNonRecoverable) >= 0)
  1328. {
  1329. pSensorReadRes->ComparisonStatus |= BIT5;
  1330. }
  1331. }
  1332. if((pSensorInfo->DeassertionEventEnablesByte2 & BIT5) == BIT5 )
  1333. {
  1334. if (CompareValues(SensorIsSigned, pSensorReadRes->SensorReading,
  1335. pSensorInfo->UpperCritical) >= 0)
  1336. {
  1337. pSensorReadRes->ComparisonStatus |= BIT4;
  1338. }
  1339. }
  1340. if((pSensorInfo->DeassertionEventEnablesByte2 & BIT4) == BIT4 )
  1341. {
  1342. if (CompareValues(SensorIsSigned, pSensorReadRes->SensorReading,
  1343. pSensorInfo->UpperNonCritical) >= 0)
  1344. {
  1345. pSensorReadRes->ComparisonStatus |= BIT3;
  1346. }
  1347. }
  1348. if((pSensorInfo->AssertionEventEnablesByte2 & BIT6) == BIT6 )
  1349. {
  1350. if (CompareValues(SensorIsSigned, pSensorReadRes->SensorReading,
  1351. pSensorInfo->LowerNonRecoverable) <= 0)
  1352. {
  1353. pSensorReadRes->ComparisonStatus |= BIT2;
  1354. }
  1355. }
  1356. if((pSensorInfo->AssertionEventEnablesByte2 & BIT5) == BIT5 )
  1357. {
  1358. if (CompareValues(SensorIsSigned, pSensorReadRes->SensorReading,
  1359. pSensorInfo->LowerCritical) <= 0)
  1360. {
  1361. pSensorReadRes->ComparisonStatus |= BIT1;
  1362. }
  1363. }
  1364. if((pSensorInfo->AssertionEventEnablesByte2 & BIT4) == BIT4 )
  1365. {
  1366. if (CompareValues(SensorIsSigned, pSensorReadRes->SensorReading,
  1367. pSensorInfo->LowerNonCritical) <= 0)
  1368. {
  1369. pSensorReadRes->ComparisonStatus |= BIT0;
  1370. }
  1371. }
  1372. pSensorReadRes->ComparisonStatus &=
  1373. ((pSensorInfo->SettableThreshMask >> 8) & 0xFF);
  1374. pSensorReadRes->OptionalStatus = 0;
  1375. // For Threshold sensor, [7:6] - reserved. Returned as 1b. Ignore on read.
  1376. pSensorReadRes->ComparisonStatus |= 0xC0;
  1377. }
  1378. else
  1379. {
  1380. //printf("---> log3\n");
  1381. pSensorReadRes->ComparisonStatus = (((uint8_t) (SensorReading & 0x00FF)) & ((uint8_t) (pSensorInfo->SettableThreshMask & 0x00FF)) );
  1382. pSensorReadRes->OptionalStatus = (((uint8_t) (SensorReading >> 8)) & ((uint8_t)(pSensorInfo->SettableThreshMask >> 8)) );
  1383. // For Discrete sensor, [7] - reserved. Returned as 1b. Ignore on read.
  1384. pSensorReadRes->OptionalStatus |= 0x80;
  1385. }
  1386. return sizeof (GetSensorReadingRes_T);
  1387. }
  1388. /*-----------------------------------------
  1389. * SetSensorReading
  1390. *-----------------------------------------*/
  1391. int
  1392. SetSensorReading ( uint8_t* pReq, uint8_t ReqLen, uint8_t* pRes)
  1393. {
  1394. printf("SetSensorReading not implement\r\n");
  1395. // SetSensorReadingReq_T* pSensorReadReq =
  1396. // ( SetSensorReadingReq_T*) pReq;
  1397. // SetSensorReadingRes_T* pSensorReadRes =
  1398. // ( SetSensorReadingRes_T*) pRes;
  1399. // SensorSharedMem_T* pSenSharedMem;
  1400. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1401. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  1402. // /* Check for the reserved bits */
  1403. // if (pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].SensorReadType == THRESHOLD_SENSOR_CLASS)
  1404. // {
  1405. // if (((ReqLen>=LEN_FOR_ASSERT_DATA) && (pSensorReadReq->AssertionEventOccuredByte2 & RESERVED_BITS_SETSENRD_ASSEVTOCCBYTE_1)) ||
  1406. // ((ReqLen>=LEN_FOR_DEASSERT_DATA) && (pSensorReadReq->DeAssertionEventOccuredByte2 & RESERVED_BITS_SETSENRD_DEASSEVTOCCBYTE_1)))
  1407. // {
  1408. // pSensorReadRes->CompletionCode = CC_INV_DATA_FIELD;
  1409. // return sizeof (*pRes);
  1410. // }
  1411. // }
  1412. // else
  1413. // {
  1414. // if (((ReqLen>=LEN_FOR_ASSERT_DATA) && (pSensorReadReq->AssertionEventOccuredByte2 & RESERVED_BITS_SETSENRD_ASSEVTOCCBYTE_2)) ||
  1415. // ((ReqLen>=LEN_FOR_DEASSERT_DATA) && (pSensorReadReq->DeAssertionEventOccuredByte2 & RESERVED_BITS_SETSENRD_DEASSEVTOCCBYTE_2)))
  1416. // {
  1417. // pSensorReadRes->CompletionCode = CC_INV_DATA_FIELD;
  1418. // return sizeof (*pRes);
  1419. // }
  1420. // }
  1421. // if (g_BMCInfo.IpmiConfig.OPMASupport == 1)
  1422. // {
  1423. // if (pSenSharedMem->GlobalSensorScanningEnable == FALSE)
  1424. // {
  1425. // pSensorReadRes->CompletionCode = CC_PARAM_NOT_SUP_IN_CUR_STATE;
  1426. // return sizeof (*pRes);
  1427. // }
  1428. // }
  1429. // /* Acquire Shared memory */
  1430. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo.SensorSharedMemMutex, WAIT_INFINITE);
  1431. // if (!pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].IsSensorPresent)
  1432. // {
  1433. // /* Release mutex for Sensor shared memory */
  1434. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1435. // pSensorReadRes->CompletionCode = CC_SDR_REC_NOT_PRESENT;
  1436. // return sizeof (*pRes);
  1437. // }
  1438. // if (ReqLen < MIN_SET_SEN_READING_CMD_LEN)
  1439. // {
  1440. // /* Release mutex for Sensor shared memory */
  1441. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1442. // pSensorReadRes->CompletionCode = CC_REQ_INV_LEN;
  1443. // return sizeof (*pRes);
  1444. // }
  1445. // /* Check if the sensor is settable */
  1446. // if (0 == GET_SETTABLE_SENSOR_BIT(pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].SensorInit))
  1447. // {
  1448. // /* Release mutex for Sensor shared memory */
  1449. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1450. // pSensorReadRes->CompletionCode = CC_INVALID_ATTEMPT_TO_SET;
  1451. // return sizeof (*pRes);
  1452. // }
  1453. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].Operation = pSensorReadReq->Operation;
  1454. // /* Set Sensor Event Data based on the Operation byte */
  1455. // switch (GET_EVENT_DATA_OP(pSensorReadReq->Operation))
  1456. // {
  1457. // case WRITE_NO_EVTDATA1:
  1458. // pSensorReadReq->EvtData1 &= 0xF0;
  1459. // /* Intentional Fall thru */
  1460. // case WRITE_EVTDATA1:
  1461. // if (LEN_FOR_EVT_DATA != ReqLen)
  1462. // {
  1463. // /* Release mutex for Sensor shared memory */
  1464. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1465. // pSensorReadRes->CompletionCode = CC_REQ_INV_LEN;
  1466. // return sizeof (*pRes);
  1467. // }
  1468. // /* Update EvtData fields */
  1469. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].EvtData1 = pSensorReadReq->EvtData1;
  1470. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].EvtData2 = pSensorReadReq->EvtData2;
  1471. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].EvtData3 = pSensorReadReq->EvtData3;
  1472. // break;
  1473. // }
  1474. // /* Check Length for Assertion Set Opetation */
  1475. // if (0 != GET_ASSERT_EVT_OP(pSensorReadReq->Operation))
  1476. // {
  1477. // if ((ReqLen < LEN_FOR_ASSERT_DATA) || (ReqLen > MAX_SET_SEN_READ_LEN))
  1478. // {
  1479. // /* Release mutex for Sensor shared memory */
  1480. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1481. // pSensorReadRes->CompletionCode = CC_REQ_INV_LEN;
  1482. // return sizeof (*pRes);
  1483. // }
  1484. // }
  1485. // /* Set Sensor Assertion Event based on the Operation byte */
  1486. // switch (GET_ASSERT_EVT_OP(pSensorReadReq->Operation))
  1487. // {
  1488. // case CLEAR_ASSERT_BITS:
  1489. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].AssertionEventOccuredByte1 &= pSensorReadReq->AssertionEventOccuredByte1;
  1490. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].AssertionEventOccuredByte2 &= pSensorReadReq->AssertionEventOccuredByte2;
  1491. // break;
  1492. // case SET_ASSERT_BITS:
  1493. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].AssertionEventOccuredByte1 |= pSensorReadReq->AssertionEventOccuredByte1;
  1494. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].AssertionEventOccuredByte2 |= pSensorReadReq->AssertionEventOccuredByte2;
  1495. // break;
  1496. // case WRITE_ASSERT_BITS:
  1497. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].AssertionEventOccuredByte1 |= pSensorReadReq->AssertionEventOccuredByte1;
  1498. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].AssertionEventOccuredByte2 |= pSensorReadReq->AssertionEventOccuredByte2;
  1499. // break;
  1500. // }
  1501. // /* Check Length for Assertion Set Opetation */
  1502. // if (0 != GET_DEASSERT_EVT_OP(pSensorReadReq->Operation))
  1503. // {
  1504. // if ((ReqLen < LEN_FOR_DEASSERT_DATA) || (ReqLen > MAX_SET_SEN_READ_LEN))
  1505. // {
  1506. // /* Release mutex for Sensor shared memory */
  1507. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1508. // pSensorReadRes->CompletionCode = CC_REQ_INV_LEN;
  1509. // return sizeof (*pRes);
  1510. // }
  1511. // }
  1512. // /* Set Sensor DeAssertion Event based on the Operation byte */
  1513. // switch (GET_DEASSERT_EVT_OP(pSensorReadReq->Operation))
  1514. // {
  1515. // case CLEAR_DEASSERT_BITS:
  1516. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].DeassertionEventOccuredByte1 &= pSensorReadReq->DeAssertionEventOccuredByte1;
  1517. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].DeassertionEventOccuredByte2 &= pSensorReadReq->DeAssertionEventOccuredByte2;
  1518. // break;
  1519. // case SET_DEASSERT_BITS:
  1520. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].DeassertionEventOccuredByte1 |= pSensorReadReq->DeAssertionEventOccuredByte1;
  1521. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].DeassertionEventOccuredByte2 |= pSensorReadReq->DeAssertionEventOccuredByte2;
  1522. // break;
  1523. // case WRITE_DEASSERT_BITS:
  1524. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].DeassertionEventOccuredByte1 |= pSensorReadReq->DeAssertionEventOccuredByte1;
  1525. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].DeassertionEventOccuredByte2 |= pSensorReadReq->DeAssertionEventOccuredByte2;
  1526. // break;
  1527. // }
  1528. // /* Check Length for Set Sensor Reading Operation */
  1529. // if (0 != GET_SETSENSOR_OP(pSensorReadReq->Operation))
  1530. // {
  1531. // if ((ReqLen < LEN_FOR_SETSENSOR_DATA) || (ReqLen > MAX_SET_SEN_READ_LEN))
  1532. // {
  1533. // /* Release mutex for Sensor shared memory */
  1534. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1535. // pSensorReadRes->CompletionCode = CC_REQ_INV_LEN;
  1536. // return sizeof (*pRes);
  1537. // }
  1538. // /* Set new Sensor Reading */
  1539. // pSenSharedMem->SensorInfo [pSensorReadReq->SensorNum].SensorReading = pSensorReadReq->SensorReading;
  1540. // }
  1541. // pSensorReadRes->CompletionCode = CC_NORMAL;
  1542. // /* Release mutex for Sensor shared memory */
  1543. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo.SensorSharedMemMutex);
  1544. // return sizeof (SetSensorReadingRes_T);
  1545. return 0;
  1546. }
  1547. /*-------------------------------------------
  1548. * GetSensorSDR
  1549. *-------------------------------------------*/
  1550. SDRRecHdr_T*
  1551. SR_GetSensorSDR (uint8_t SensorNum)
  1552. {
  1553. SDRRecHdr_T* SDRRec;
  1554. /* Search for the record containing the sensor */
  1555. SDRRec = SDR_GetFirstSDRRec ();
  1556. while (0 != SDRRec)
  1557. {
  1558. switch (SDRRec->Type)
  1559. {
  1560. case FULL_SDR_REC :
  1561. if ((( FullSensorRec_T*) SDRRec)->SensorNum == SensorNum)
  1562. {
  1563. return SDRRec;
  1564. }
  1565. break;
  1566. case COMPACT_SDR_REC:
  1567. {
  1568. uint16_t SharedRecs = ((( CompactSensorRec_T*) SDRRec)->RecordSharing) &
  1569. SHARED_RECD_COUNT;
  1570. if ((SensorNum == (( CompactSensorRec_T*) SDRRec)->SensorNum ) ||
  1571. ((SensorNum >= ((( CompactSensorRec_T*) SDRRec)->SensorNum )) &&
  1572. (SensorNum < ((( CompactSensorRec_T*) SDRRec)->SensorNum + SharedRecs)))
  1573. )
  1574. {
  1575. return SDRRec;
  1576. }
  1577. }
  1578. break;
  1579. default :
  1580. break;
  1581. }
  1582. /* Get the next record */
  1583. SDRRec = SDR_GetNextSDRRec (SDRRec);
  1584. if (0 == SDRRec)
  1585. {
  1586. return 0;
  1587. }
  1588. }
  1589. return 0;
  1590. }
  1591. ///**
  1592. // * @brief Update global variables with number sensors.
  1593. //**/
  1594. //static void
  1595. //FindNumSensors ()
  1596. //{
  1597. // SDRRecHdr_T* pSDRRec;
  1598. // FullSensorRec_T* pFSR;
  1599. // CompactSensorRec_T* pCSR;
  1600. // pFSR = 0;
  1601. // pCSR = 0;
  1602. // /* Get First SDR Record */
  1603. // pSDRRec = SDR_GetFirstSDRRec ();
  1604. // while (0 != pSDRRec)
  1605. // {
  1606. // switch (pSDRRec->Type)
  1607. // {
  1608. // case FULL_SDR_REC :
  1609. // pFSR = ( FullSensorRec_T*) pSDRRec;
  1610. // if (THRESHOLD_SENSOR_CLASS == pFSR->EventTypeCode)
  1611. // {
  1612. // g_BMCInfo.SenConfig.NumThreshSensors++;
  1613. // }
  1614. // else
  1615. // {
  1616. // g_BMCInfo.SenConfig.NumNonThreshSensors++;
  1617. // }
  1618. // break;
  1619. // case COMPACT_SDR_REC :
  1620. // pCSR = ( CompactSensorRec_T*) pSDRRec;
  1621. // if (THRESHOLD_SENSOR_CLASS == pCSR->EventTypeCode)
  1622. // {
  1623. // g_BMCInfo.SenConfig.NumThreshSensors += ( (pCSR->RecordSharing) & SHARED_RECD_COUNT);
  1624. // }
  1625. // else
  1626. // {
  1627. // g_BMCInfo.SenConfig.NumNonThreshSensors += ( (pCSR->RecordSharing) & SHARED_RECD_COUNT);
  1628. // }
  1629. // break;
  1630. // default:
  1631. // break;
  1632. // }
  1633. // /* Get the next record */
  1634. // pSDRRec = SDR_GetNextSDRRec (pSDRRec);
  1635. // }
  1636. // printf("Thereshold Sensors = %d\n",g_BMCInfo.SenConfig.NumThreshSensors);
  1637. // printf("Non Thershold Sensors = %d\n",g_BMCInfo.SenConfig.NumNonThreshSensors);
  1638. // return;
  1639. //}
  1640. int
  1641. GetRecordIdsforDCMISensor (uint8_t EntityID,uint8_t SensorType, uint8_t EntityInstance,
  1642. uint8_t StartingEntityInstance, uint16_t* pBuf, uint8_t* pTotalValidInstances)
  1643. {
  1644. printf("GetRecordIdsforDCMISensor not implement\r\n");
  1645. // int i, ValidInstances;
  1646. // SensorSharedMem_T* pSenSharedMem;
  1647. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1648. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  1649. // if (0 != EntityInstance)
  1650. // {
  1651. // *pTotalValidInstances = 0;
  1652. // ValidInstances = 0;
  1653. // /* Acquire Shared memory to populate sensor information */
  1654. // //OS_ACQUIRE_MUTEX(m_hSensorSharedMemMutex, SHARED_MEM_TIMEOUT);
  1655. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo[BMCInst].SensorSharedMemMutex, WAIT_INFINITE);
  1656. // for (i = 0; i < MAX_SENSOR_NUMBERS + 1; i++ )
  1657. // {
  1658. // if ((TRUE == pSenSharedMem->SensorInfo [i].IsDCMITempsensor) && (pSenSharedMem->SensorInfo[i].SDRRec->Type == FULL_SDR_REC) )
  1659. // {
  1660. // if(SensorType != pSenSharedMem->SensorInfo[i].SensorTypeCode)
  1661. // {
  1662. // /*Check the Sensor type*/
  1663. // continue;
  1664. // }
  1665. // if ((((EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (EntityID == IPMI_INLET_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_INLET_TEMP_ENTITY_ID))) ||
  1666. // (((EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (EntityID == IPMI_CPU_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_CPU_TEMP_ENTITY_ID))) ||
  1667. // (((EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID))))
  1668. // {
  1669. // *pTotalValidInstances += 1;
  1670. // if (EntityInstance == pSenSharedMem->SensorInfo [i].EntiryInstance)
  1671. // {
  1672. // pBuf [0] = pSenSharedMem->SensorInfo [i].RecordID;
  1673. // ValidInstances = 1;
  1674. // }
  1675. // }
  1676. // }
  1677. // }
  1678. // /* Release mutex for Sensor shared memory */
  1679. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo[BMCInst].SensorSharedMemMutex);
  1680. // return ValidInstances;
  1681. // }
  1682. // else
  1683. // {
  1684. // *pTotalValidInstances = 0;
  1685. // ValidInstances = 0;
  1686. // /* Acquire Shared memory to populate sensor information */
  1687. // //OS_ACQUIRE_MUTEX(m_hSensorSharedMemMutex, SHARED_MEM_TIMEOUT);
  1688. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo[BMCInst].SensorSharedMemMutex, WAIT_INFINITE);
  1689. // for (i = StartingEntityInstance; i < MAX_SENSOR_NUMBERS + 1; i++ )
  1690. // {
  1691. // if ((TRUE == pSenSharedMem->SensorInfo [i].IsDCMITempsensor) && (pSenSharedMem->SensorInfo[i].SDRRec->Type == FULL_SDR_REC) )
  1692. // {
  1693. // if(SensorType != pSenSharedMem->SensorInfo[i].SensorTypeCode)
  1694. // {
  1695. // /*Check the Sensor type*/
  1696. // continue;
  1697. // }
  1698. // if ((((EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (EntityID == IPMI_INLET_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_INLET_TEMP_ENTITY_ID))) ||
  1699. // (((EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (EntityID == IPMI_CPU_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_CPU_TEMP_ENTITY_ID))) ||
  1700. // (((EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID))))
  1701. // {
  1702. // *pTotalValidInstances += 1;
  1703. // if (ValidInstances < 8)
  1704. // {
  1705. // pBuf [ValidInstances] = pSenSharedMem->SensorInfo [i].RecordID;
  1706. // ValidInstances += 1;
  1707. // }
  1708. // }
  1709. // }
  1710. // }
  1711. // /* Release mutex for Sensor shared memory */
  1712. // //OS_RELEASE_MUTEX(m_hSensorSharedMemMutex);
  1713. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo[BMCInst].SensorSharedMemMutex);
  1714. // return (ValidInstances > 8) ? 8: ValidInstances;
  1715. // }
  1716. return 0;
  1717. }
  1718. int GetDCMITempReading(uint8_t EntityID,uint8_t SensorType, uint8_t EntityInstance,
  1719. uint8_t StartingEntityInstance, uint8_t* pBuf, uint8_t* pTotalValidInstances)
  1720. {
  1721. printf("GetDCMITempReading not implement\r\n");
  1722. // int i, ValidInstances,j = 0;
  1723. // SensorSharedMem_T* pSenSharedMem;
  1724. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  1725. // pSenSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem; //m_hSensorSharedMem;
  1726. // SDRRecHdr_T* pSDRRec;
  1727. // FullSensorRec_T* FullSDR;
  1728. // float convreading = 0;
  1729. // uint8_t MinReading = 0, MaxReading = 0,Linear = 0;
  1730. // if (0 != EntityInstance)
  1731. // {
  1732. // *pTotalValidInstances = 0;
  1733. // ValidInstances = 0;
  1734. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo[BMCInst].SensorSharedMemMutex, WAIT_INFINITE);
  1735. // for (i = 0; i < MAX_SENSOR_NUMBERS + 1; i++ )
  1736. // {
  1737. // if ((TRUE == pSenSharedMem->SensorInfo [i].IsDCMITempsensor) && (pSenSharedMem->SensorInfo[i].SDRRec->Type == FULL_SDR_REC) )
  1738. // {
  1739. // if(SensorType != pSenSharedMem->SensorInfo[i].SensorTypeCode)
  1740. // {
  1741. // /*Check the Sensor type*/
  1742. // continue;
  1743. // }
  1744. // if ((((EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (EntityID == IPMI_INLET_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_INLET_TEMP_ENTITY_ID))) ||
  1745. // (((EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (EntityID == IPMI_CPU_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_CPU_TEMP_ENTITY_ID))) ||
  1746. // (((EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID))))
  1747. // {
  1748. // *pTotalValidInstances += 1;
  1749. // if (EntityInstance == pSenSharedMem->SensorInfo [i].EntiryInstance)
  1750. // {
  1751. // if( !( pSenSharedMem->SensorInfo[i].EventFlags & 0x40) || (pSenSharedMem->SensorInfo[i].EventFlags & 0x20) )
  1752. // {
  1753. // printf("event flag is disabled\n");
  1754. // pBuf[DCMI_TEMP_READING] = 0;
  1755. // pBuf[DCMI_INST_NUMBER] = 0;
  1756. // }
  1757. // else
  1758. // {
  1759. // pSDRRec = GetSDRRec(pSenSharedMem->SensorInfo[i].SDRRec->ID,BMCInst);
  1760. //
  1761. // FullSDR = ( FullSensorRec_T *)pSDRRec;
  1762. // MinReading = FullSDR->MinReading;
  1763. // MaxReading = FullSDR->MaxReading;
  1764. // Linear = FullSDR->Linearization;
  1765. //
  1766. // ipmi_conv_reading(pSenSharedMem->SensorInfo[i].SDRRec->Type, pSenSharedMem->SensorInfo[i].SensorReading, &convreading, MinReading,MaxReading, pSenSharedMem->SensorInfo[i].Units1,Linear, pSenSharedMem->SensorInfo[i].M_LSB,
  1767. // pSenSharedMem->SensorInfo[i].B_LSB, pSenSharedMem->SensorInfo[i].M_MSB_Tolerance, pSenSharedMem->SensorInfo[i].B_MSB_Accuracy, pSenSharedMem->SensorInfo[i].RExp_BExp);
  1768. // pBuf [DCMI_TEMP_READING] = (int8_t)convreading;
  1769. // pBuf [DCMI_INST_NUMBER] = EntityInstance;
  1770. // }
  1771. // ValidInstances = 1;
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. // /* Release mutex for Sensor shared memory */
  1777. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo[BMCInst].SensorSharedMemMutex);
  1778. // return ValidInstances;
  1779. // }
  1780. // else
  1781. // {
  1782. // *pTotalValidInstances = 0;
  1783. // ValidInstances = 0;
  1784. // OS_THREAD_MUTEX_ACQUIRE(&g_BMCInfo[BMCInst].SensorSharedMemMutex, WAIT_INFINITE);
  1785. // for (i = StartingEntityInstance; i < MAX_SENSOR_NUMBERS + 1; i++ )
  1786. // {
  1787. // if ((TRUE == pSenSharedMem->SensorInfo [i].IsDCMITempsensor) && (pSenSharedMem->SensorInfo[i].SDRRec->Type == FULL_SDR_REC) )
  1788. // {
  1789. // if(SensorType != pSenSharedMem->SensorInfo[i].SensorTypeCode)
  1790. // {
  1791. // /*Check the Sensor type*/
  1792. // continue;
  1793. // }
  1794. // if ((((EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (EntityID == IPMI_INLET_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_INLET_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_INLET_TEMP_ENTITY_ID))) ||
  1795. // (((EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (EntityID == IPMI_CPU_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_CPU_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_CPU_TEMP_ENTITY_ID))) ||
  1796. // (((EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID)) && ((pSenSharedMem->SensorInfo [i].EntityID == DCMI_BASEBOARD_TEMP_ENTITY_ID) || (pSenSharedMem->SensorInfo [i].EntityID == IPMI_BASEBOARD_TEMP_ENTITY_ID))))
  1797. // {
  1798. // *pTotalValidInstances += 1;
  1799. // if (ValidInstances < 8)
  1800. // {
  1801. // if( !( pSenSharedMem->SensorInfo[i].EventFlags & 0x40) || (pSenSharedMem->SensorInfo[i].EventFlags & 0x20) )
  1802. // {
  1803. // pBuf[DCMI_TEMP_READING + j] = 0;
  1804. // pBuf[DCMI_INST_NUMBER + j] = 0;
  1805. // j = j+2;
  1806. // }
  1807. // else
  1808. // {
  1809. // pSDRRec = GetSDRRec(pSenSharedMem->SensorInfo[i].SDRRec->ID,BMCInst);
  1810. // FullSDR = ( FullSensorRec_T *)pSDRRec;
  1811. // MinReading = FullSDR->MinReading;
  1812. // MaxReading = FullSDR->MaxReading;
  1813. // Linear = FullSDR->Linearization;
  1814. //
  1815. // ipmi_conv_reading(pSenSharedMem->SensorInfo[i].SDRRec->Type, pSenSharedMem->SensorInfo[i].SensorReading, &convreading, MinReading,MaxReading, pSenSharedMem->SensorInfo[i].Units1,Linear, pSenSharedMem->SensorInfo[i].M_LSB,
  1816. // pSenSharedMem->SensorInfo[i].B_LSB, pSenSharedMem->SensorInfo[i].M_MSB_Tolerance, pSenSharedMem->SensorInfo[i].B_MSB_Accuracy, pSenSharedMem->SensorInfo[i].RExp_BExp);
  1817. //
  1818. // pBuf[ j++] = (int8_t)convreading;
  1819. // pBuf[ j++] = pSenSharedMem->SensorInfo[i].EntiryInstance;
  1820. // TDBG("j value %d\n",j);
  1821. // }
  1822. // ValidInstances += 1;
  1823. // }
  1824. // }
  1825. // }
  1826. // }
  1827. // OS_THREAD_MUTEX_RELEASE(&g_BMCInfo[BMCInst].SensorSharedMemMutex);
  1828. // return (ValidInstances > 8) ? 8: ValidInstances;
  1829. // }
  1830. return 0;
  1831. }
  1832. #endif /* SENSOR_DEVICE */