Sensor.c 79 KB

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