Events.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. * Events.c
  16. * Event Commands Handler
  17. *
  18. * Author: Bakka Ravinder Reddy <bakkar@ami.com>
  19. *
  20. *****************************************************************/
  21. #define ENABLE_DEBUG_MACROS 0
  22. #include "Types.h"
  23. #include "Events.h"
  24. #include "MsgHndlr.h"
  25. #include "IPMIDefs.h"
  26. #include "Support.h"
  27. #include "SEL.h"
  28. #include "IPMI_SEL.h"
  29. #include "SELRecord.h"
  30. #include "Message.h"
  31. #include "IPMI_Events.h"
  32. #include "SharedMem.h"
  33. #include "PEF.h"
  34. #include "IPMI_Main.h"
  35. #include "AppDevice.h"
  36. #include "IPMI_KCS.h"
  37. //#include "SensorMonitor.h"
  38. #include "IPMIConf.h"
  39. #include "featuredef.h"
  40. #include "PDKCmdsAccess.h"
  41. /* Reserved bit macro definitions */
  42. #define RESERVED_BITS_SETEVENTRECEIVER 0xFC //(BIT7 | BIT6 | BIT5 | BIT4 | BIT3 | BIT2)
  43. #if EVENT_PROCESSING_DEVICE == 1
  44. /*** Local Definitions ***/
  45. #define EVTDATA_LENGTH_SYS_INTERFACE 0x08
  46. #define EVTDATA_LENGTH_NON_SYS_INTERFACE 0x07
  47. #define LUN_MASK 0x03
  48. #define UNSPECIFIED_EVT_DATA 0xFF
  49. /*---------------------------------------
  50. * SetEventReceiver
  51. *---------------------------------------*/
  52. int
  53. SetEventReceiver (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  54. {
  55. _FAR_ MsgPkt_T Msg;
  56. HQueue_T hSMHndlr_Q;
  57. _NEAR_ SetEvtRcvReq_T* pSetEvtReq = (_NEAR_ SetEvtRcvReq_T*) pReq;
  58. _FAR_ BMCSharedMem_T* pSharedMem = BMC_GET_SHARED_MEM(BMCInst);
  59. /* Check for the reserved bytes should b zero */
  60. if ( 0 != (pSetEvtReq->RcvLUN & RESERVED_BITS_SETEVENTRECEIVER ) )
  61. {
  62. pRes[0] = CC_INV_DATA_FIELD;
  63. return sizeof(*pRes);
  64. }
  65. pSharedMem->EvRcv_SlaveAddr = pSetEvtReq->RcvSlaveAddr;
  66. pSharedMem->EvRcv_LUN = 0;
  67. pSharedMem->EvRcv_LUN |= (pSetEvtReq->RcvLUN & LUN_MASK);
  68. Msg.Param = PARAM_REARM_ALL_SENSORS;
  69. Msg.Size = 0;
  70. GetQueueHandle(SM_HNDLR_Q,&hSMHndlr_Q,BMCInst);
  71. /* Post Msg to sensormonitor task Thread to rearm all sensors */
  72. if ( -1 != hSMHndlr_Q )
  73. {
  74. PostMsg(&Msg, SM_HNDLR_Q, BMCInst);
  75. pRes[0] = CC_NORMAL;
  76. }else
  77. {
  78. pRes[0] = 0xFF;
  79. }
  80. return sizeof(*pRes);
  81. }
  82. /*---------------------------------------
  83. * GetEventReceiver
  84. *---------------------------------------*/
  85. int
  86. GetEventReceiver (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  87. {
  88. _NEAR_ GetEvtRcvRes_T* pGetEvtRes = (_NEAR_ GetEvtRcvRes_T*) pRes;
  89. _FAR_ BMCSharedMem_T* pSharedMem = BMC_GET_SHARED_MEM(BMCInst);
  90. pGetEvtRes->RcvSlaveAddr = pSharedMem->EvRcv_SlaveAddr;
  91. pGetEvtRes->RcvLUN = pSharedMem->EvRcv_LUN;
  92. pGetEvtRes->CompletionCode = CC_NORMAL;
  93. return sizeof(GetEvtRcvRes_T);
  94. }
  95. /*---------------------------------------
  96. * PlatformEventMessage
  97. *---------------------------------------*/
  98. int
  99. PlatformEventMessage (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
  100. {
  101. SELEventRecord_T EvtRec;
  102. AddSELRes_T AddSelRes;
  103. MsgPkt_T MsgToPEF;
  104. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  105. IPMIMsgHdr_T* pIPMIMsgHdr = NULL;
  106. INT8U *curchannel;
  107. // Request Length varies for channel (from which the request was received)
  108. // software ID exist only for Sys IFC, for all other IFC, it won't
  109. EvtRec.EvtData2 = UNSPECIFIED_EVT_DATA;
  110. EvtRec.EvtData3 = UNSPECIFIED_EVT_DATA;
  111. OS_THREAD_TLS_GET(g_tls.CurChannel,curchannel);
  112. if ( ((pBMCInfo->IpmiConfig.SYSIfcSupport == 0x01 && (*curchannel & 0xF) == SYS_IFC_CHANNEL)
  113. && ((ReqLen < EVTDATA_LENGTH_SYS_INTERFACE - 2) || (EVTDATA_LENGTH_SYS_INTERFACE < ReqLen)) )
  114. ||(((*curchannel & 0xF) != SYS_IFC_CHANNEL)
  115. && ((ReqLen < EVTDATA_LENGTH_NON_SYS_INTERFACE - 2) || (EVTDATA_LENGTH_NON_SYS_INTERFACE < ReqLen)) ) )
  116. {
  117. pRes[0] = CC_REQ_INV_LEN;
  118. return sizeof(*pRes);
  119. }
  120. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->SELConfig.SELMutex, WAIT_INFINITE);
  121. MsgToPEF.Channel = *curchannel & 0xF;
  122. MsgToPEF.Cmd = 0;
  123. if (pBMCInfo->IpmiConfig.SYSIfcSupport == 0x01 && SYS_IFC_CHANNEL == (*curchannel & 0xF))
  124. {
  125. EvtRec.GenID [0] = *pReq| BIT0; // system software ID
  126. EvtRec.GenID [1] = 0;
  127. _fmemcpy ((_FAR_ INT8U*)&EvtRec.EvMRev, &pReq [1], ReqLen - 1);
  128. }
  129. else
  130. { // RqAddr & LUN are already in the Msg Hdr, use that here
  131. pIPMIMsgHdr = ((IPMIMsgHdr_T *) &pReq [0] ) -1;
  132. EvtRec.GenID [0] = pIPMIMsgHdr->ReqAddr;
  133. EvtRec.GenID [1] = ((*curchannel & 0xF) << 4) | (pIPMIMsgHdr->RqSeqLUN & 0x3);
  134. _fmemcpy ((_FAR_ INT8U*)&EvtRec.EvMRev , &pReq [0], ReqLen);
  135. }
  136. EvtRec.hdr.Type = 0x02; /* Mark as System Event Record */
  137. EvtRec.hdr.TimeStamp = GetSelTimeStamp(BMCInst);
  138. LockedAddSELEntry ((_NEAR_ INT8U*)&EvtRec, sizeof (SELEventRecord_T),
  139. (_NEAR_ INT8U*)&AddSelRes, (SYS_IFC_CHANNEL == (*curchannel & 0xF) ? TRUE : FALSE), POST_SEL_AND_PEF, BMCInst);
  140. EvtRec.hdr.ID = AddSelRes.RecID;
  141. if (AddSelRes.CompletionCode == CC_PARAM_NOT_SUP_IN_CUR_STATE)
  142. {
  143. // CC_PARAM_NOT_SUP_IN_CUR_STATE will be returned when SEL is disabled.
  144. EvtRec.hdr.ID = 0xFFFF;
  145. }
  146. else if (AddSelRes.CompletionCode != CC_NORMAL)
  147. {
  148. pRes [0] = AddSelRes.CompletionCode;
  149. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SELConfig.SELMutex);
  150. return sizeof (*pRes);
  151. }
  152. _fmemcpy (MsgToPEF.Data, (_FAR_ INT8U*)&EvtRec, sizeof (SELEventRecord_T));
  153. MsgToPEF.Size = sizeof (SELEventRecord_T);
  154. MsgToPEF.Param = PARAM_PLATFORM_EVT_MSG;
  155. // the AddSELEntry() function alreadys forwards the event to PEF, we shouldn't pass it again to the PEF here.
  156. // Otherwise, the PEF will get and act on the event twice.
  157. //PostMsgNonBlock (&MsgToPEF, hPEFTask_Q);
  158. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->EventMutex,WAIT_INFINITE);
  159. //30069
  160. /* Post to the Event message queue only if event message buffer enabled */
  161. if ((BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables & 0x04) &&
  162. (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg < EVT_MSG_BUF_SIZE))
  163. {
  164. PostMsgNonBlock (&MsgToPEF, EVT_MSG_Q,BMCInst);
  165. BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg++;
  166. }
  167. if (BMC_GET_SHARED_MEM (BMCInst)->GlobalEnables & 0x04)
  168. {
  169. /* If Event MessageBuffer is Full set the SMS_ATN bit */
  170. if (BMC_GET_SHARED_MEM (BMCInst)->NumEvtMsg >= EVT_MSG_BUF_SIZE)
  171. {
  172. //SET_SMS_ATN ();
  173. if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  174. {
  175. SET_SMS_ATN (0, BMCInst);
  176. if(g_corefeatures.kcs_obf_bit == ENABLED)
  177. {
  178. SET_OBF (0, BMCInst);
  179. }
  180. }
  181. if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  182. {
  183. SET_SMS_ATN (1, BMCInst);
  184. if(g_corefeatures.kcs_obf_bit == ENABLED)
  185. {
  186. SET_OBF (1, BMCInst);
  187. }
  188. }
  189. if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  190. {
  191. SET_SMS_ATN (2, BMCInst);
  192. if(g_corefeatures.kcs_obf_bit == ENABLED)
  193. {
  194. SET_OBF (2, BMCInst);
  195. }
  196. }
  197. }
  198. }
  199. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->EventMutex);
  200. // To send notification to CIM
  201. if(g_PDKCIMEventHandle[PDKCIMEVENT_NOTIFYSERVERUPDATETOCIM] != NULL)
  202. {
  203. uint8 CMD;
  204. // Set bits for SEL Event & Add operation
  205. CMD = 0x21;
  206. ((int(*)(uint8, uint16))g_PDKCIMEventHandle[PDKCIMEVENT_NOTIFYSERVERUPDATETOCIM])(CMD, AddSelRes.RecID);
  207. }
  208. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->SELConfig.SELMutex);
  209. /* Fill the completion code */
  210. pRes [0] = CC_NORMAL;
  211. return sizeof(*pRes);
  212. }
  213. #endif /* EVENT_PROCESSING_DEVICE */