WDT.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. * WDT.c
  17. * WadtchDog TimeOut function
  18. *
  19. * Author: Govind Kothandapani <govindk@ami.com>
  20. * : Rama Bisa <ramab@ami.com>
  21. * : Basavaraj Astekar <basavaraja@ami.com>
  22. * : Bakka Ravinder Reddy <bakkar@ami.com>
  23. *
  24. *****************************************************************/
  25. #include "WDT.h"
  26. #include "com_IPMIDefs.h"
  27. #include "ChassisDevice.h"
  28. #include <stdio.h>
  29. /*** Local macro definitions ***/
  30. #define PRE_TIMEOUT 1
  31. #define WDT_TIMEOUT 2
  32. #define PRETIMEOUT_ACTION_TAKEN 0x08
  33. #define TIMEOUT_NO_ACTION_TAKEN 0x00
  34. #define TIMEOUT_ACTION_HARD_RESET 0x01
  35. #define TIMEOUT_ACTION_POWER_DOWN 0x02
  36. #define TIMEOUT_ACTION_POWER_CYCLE 0x03
  37. #define PRE_TIMEOUT_SMI 0x10
  38. #define PRE_TIMEOUT_NMI_DIAG 0x20
  39. #define PRE_TIMEOUT_MESSAGING_INTR 0x30
  40. /*** Global variables **/
  41. WDTTmrMgr_T g_WDTTmrMgr;
  42. /*----------------------------------------------------------------
  43. * WatchDog2 Event Offsets
  44. *---------------------------------------------------------------*/
  45. #define IPMI_WDT_TIMER_EXPIRED 0x00 //Watch Dog Expired Status only offset
  46. #define IPMI_WDT_HARD_RESET 0x01
  47. #define IPMI_WDT_POWER_DOWN 0x02
  48. #define IPMI_WDT_POWER_CYCLE 0x03
  49. #define IPMI_WDT_TIMER_INTERRUPT 0x08
  50. #define MAX_WDT_MS_VALUE(Hertz) (0xFFFFFFFF * 1000)/Hertz
  51. /*** Function Prototypes ***/
  52. //static void WDTTmrAction (uint8_t TmrAction, int BMCInst);
  53. /* Declare Thread Mutex */
  54. //OS_THREAD_MUTEX_DECLARE(hWDTSharedMemMutex);
  55. /**
  56. * WDTTimerTask
  57. **/
  58. void WDTTimerTask (void *pArg)
  59. {
  60. // int *inst = (int*) pArg;
  61. // int BMCInst = *inst;
  62. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  63. // uint32_t WDTInterval = 0,WDTPreInterval = 0,jiffycmp = 0;
  64. // long long jiffyvalue=0,jiffystart = 0;
  65. // unsigned long Hertz = sysconf(_SC_CLK_TCK);
  66. // prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  67. // /* Get the Shared memory mutex handle */
  68. // OS_THREAD_MUTEX_INIT(pBMCInfo->hWDTSharedMemMutex, PTHREAD_MUTEX_RECURSIVE);
  69. // while(TRUE)
  70. // {
  71. // /* Will be waiting till the Watchdog timer is armed*/
  72. // sem_wait(&pBMCInfo->WDTSem);
  73. // /* If no timer to process return */
  74. // if (FALSE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent)
  75. // {
  76. // continue;
  77. // }
  78. // WDTInterval = pBMCInfo->WDTConfig.InitCountDown * WDT_COUNT_MS;
  79. // if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
  80. // {
  81. // WDTPreInterval = WDTInterval+1;
  82. // }
  83. // else
  84. // {
  85. // WDTPreInterval = 1000 * pBMCInfo->WDTConfig.PreTimeOutInterval;
  86. // }
  87. // if(GetJiffySysCtlvalue(JIFFY_VALUE,&jiffyvalue) == 1)
  88. // {
  89. // IPMI_ERROR("Error in getting Jiffy value \n");
  90. // return 0;
  91. // }
  92. // jiffystart = jiffyvalue;
  93. // while(1)
  94. // {
  95. // if(GetJiffySysCtlvalue(JIFFY_VALUE,&jiffyvalue) == 1)
  96. // {
  97. // IPMI_ERROR("Error in getting Jiffy value \n");
  98. // return 0;
  99. // }
  100. // if (pBMCInfo->HostOFFStopWDT == TRUE)
  101. // {
  102. // pBMCInfo->HostOFFStopWDT = FALSE;
  103. // break;
  104. // }
  105. // if(pBMCInfo->SetWDTUpdated == TRUE && (TRUE == BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent))
  106. // {
  107. // jiffystart = jiffyvalue;
  108. // WDTInterval = pBMCInfo->WDTConfig.InitCountDown * WDT_COUNT_MS;
  109. // if ((pBMCInfo->WDTConfig.TmrActions & 0x70) == 0)
  110. // {
  111. // WDTPreInterval = WDTInterval+1;
  112. //
  113. // }
  114. // else
  115. // {
  116. // WDTPreInterval = 1000 * pBMCInfo->WDTConfig.PreTimeOutInterval;
  117. // }
  118. // pBMCInfo->SetWDTUpdated = FALSE;
  119. // }
  120. // else if(pBMCInfo->SetWDTUpdated == TRUE && (FALSE== BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent))
  121. // {
  122. // /* Restore Initial countdown value */
  123. // g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown;
  124. // break;
  125. // }
  126. // if(jiffyvalue < jiffystart)
  127. // {
  128. // /* To handle Jiffy Overflow condition */
  129. // jiffycmp = (MAX_WDT_MS_VALUE(Hertz) -jiffystart) + jiffyvalue;
  130. // }
  131. // else
  132. // {
  133. // jiffycmp = jiffyvalue - jiffystart;
  134. // }
  135. // if((jiffycmp > WDTInterval) ||(jiffycmp > (WDTInterval-WDTPreInterval)))
  136. // {
  137. // if((jiffycmp > (WDTInterval-WDTPreInterval)) && (pBMCInfo->WDTPreTmtStat == FALSE)
  138. // && ((pBMCInfo->WDTConfig.TmrActions & 0x70) != 0))
  139. // {
  140. // /* take pretimeout actions */
  141. // if(pBMCInfo->TriggerEvent.WDTTimeExpire)
  142. // {
  143. // if(0 == send_signal_by_name("Adviserd",SIGUSR2))
  144. // {
  145. // TDBG("Signal Sent successfully to adviser to start recording video\n");
  146. // }
  147. // else
  148. // {
  149. // TDBG("Cannot Send Signal to adviser to start recording video\n");
  150. // }
  151. // }
  152. // WDTTmrAction (g_WDTTmrMgr.WDTTmr.TmrActions & 0x70, BMCInst);
  153. // pBMCInfo->WDTPreTmtStat = TRUE;
  154. // }
  155. // else if(jiffycmp > WDTInterval)
  156. // {
  157. // g_WDTTmrMgr.TmrPresent = FALSE;
  158. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->hWDTSharedMemMutex, WAIT_INFINITE)
  159. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning=FALSE;
  160. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent =FALSE;
  161. // // Modify ARP status to resume the thread
  162. // // after receiving set Watchdog Timer command
  163. // //BMC_GET_SHARED_MEM(BMCInst)->GratArpStatus = RESUME_ARPS;
  164. //
  165. // uint8_t i = 0;
  166. // for (i = 0; i < MAX_LAN_CHANNELS; i++)
  167. // {
  168. // if((pBMCInfo->LanIfcConfig[i].Enabled == TRUE)
  169. // && (pBMCInfo->LanIfcConfig[i].Up_Status == LAN_IFC_UP))
  170. // {
  171. // BMC_GET_SHARED_MEM(BMCInst)->ArpSuspendStatus[i] = RESUME_ARPS;
  172. // UpdateArpStatus(pBMCInfo->LanIfcConfig[i].Ethindex, BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning, BMCInst);
  173. // }
  174. // }
  175. //
  176. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->hWDTSharedMemMutex);
  177. // /* Take WDT timeout Actions */
  178. // pBMCInfo->WDTPreTmtStat = FALSE;
  179. // g_WDTTmrMgr.TmrInterval = 0;
  180. // if(pBMCInfo->TriggerEvent.WDTTimeExpire)
  181. // {
  182. // if(0 == send_signal_by_name("Adviserd",SIGUSR2))
  183. // {
  184. // TDBG("Signal Sent successfully to adviser to start recording video\n");
  185. // }
  186. // else
  187. // {
  188. // TDBG("Cannot Send Signal to adviser to start recording video\n");
  189. // }
  190. // }
  191. // WDTTmrAction (g_WDTTmrMgr.WDTTmr.TmrActions & 0x07, BMCInst);
  192. // break;
  193. // }
  194. //
  195. // }
  196. // if((jiffycmp -WDTInterval) > 20)
  197. // {
  198. // /* Made to sleep for 100ms to reduce CPU Usage */
  199. // usleep(WDT_SLEEP_TIME);
  200. // g_WDTTmrMgr.TmrInterval = pBMCInfo->WDTConfig.InitCountDown - (jiffycmp/WDT_COUNT_MS);
  201. // }
  202. // }
  203. // }
  204. }
  205. ///**
  206. // * @brief Takes action depending on the argument.
  207. // * @param TmrAction Timeout action.
  208. // **/
  209. //static void
  210. //WDTTmrAction (uint8_t TmrAction, int BMCInst)
  211. //{
  212. // log("WDTTmrAction not implement\r\n");
  213. // int i = 0;
  214. // uint8_t u8EventOffset;
  215. // uint8_t readFlags = 0;
  216. // BMCInfo_t* pBMCInfo = &g_BMCInfo;
  217. // SensorInfo_T* pSensorInfo;
  218. // SensorSharedMem_T* pSMSharedMem;
  219. // if(IsCardInFlashMode()){
  220. // return;
  221. // }
  222. //
  223. // if (TmrAction & 0x70)
  224. // {
  225. // pBMCInfo->WDTConfig.PreTimeoutActionTaken = g_WDTTmrMgr.WDTTmr.PreTimeoutActionTaken = PRETIMEOUT_ACTION_TAKEN;
  226. // if (pBMCInfo->IpmiConfig.KCS1IfcSupport == 1)
  227. // {
  228. // SET_SMS_ATN (0, BMCInst);
  229. // if(g_corefeatures.kcs_obf_bit == ENABLED)
  230. // {
  231. // SET_OBF (0, BMCInst);
  232. // }
  233. // }
  234. // if (pBMCInfo->IpmiConfig.KCS2IfcSupport == 1)
  235. // {
  236. // SET_SMS_ATN (1, BMCInst);
  237. // if(g_corefeatures.kcs_obf_bit == ENABLED)
  238. // {
  239. // SET_OBF (1, BMCInst);
  240. // }
  241. // }
  242. // if (pBMCInfo->IpmiConfig.KCS3IfcSuppport == 1)
  243. // {
  244. // SET_SMS_ATN (2, BMCInst);
  245. // if(g_corefeatures.kcs_obf_bit == ENABLED)
  246. // {
  247. // SET_OBF (2, BMCInst);
  248. // }
  249. // }
  250. // }
  251. // else
  252. // {
  253. // pBMCInfo->WDTConfig.ExpirationFlag |= 0x1 << (pBMCInfo->WDTConfig.TmrUse & 0x07);
  254. // // Based on the IPMI spec 27.7, the WDT expiration flag should not be preserved on any AC cycle.
  255. // // update the WDT expiration flag in the global memory pool, not persistant in the flash
  256. // g_WDTTmrMgr.WDTTmr.ExpirationFlag |= 0x1 << (pBMCInfo->WDTConfig.TmrUse & 0x07);
  257. // }
  258. // // setup sensor event offset
  259. // u8EventOffset = TmrAction;
  260. // if(g_corefeatures.wdt_flush_support == ENABLED )
  261. // {
  262. // FlushIPMI((uint8_t*)&pBMCInfo->WDTConfig,(uint8_t*)&pBMCInfo->WDTConfig,pBMCInfo->IPMIConfLoc.WDTDATAddr,
  263. // sizeof(WDTConfig_T),BMCInst);
  264. // }
  265. // if(g_PDKHandle[PDK_BEFOREWATCHDOGACTION] != NULL)
  266. // {
  267. // if( (((int(*)(uint8_t,WDTTmrMgr_T*,int))g_PDKHandle[PDK_BEFOREWATCHDOGACTION]) (TmrAction, &g_WDTTmrMgr,BMCInst)) != 0)
  268. // {
  269. // return;
  270. // }
  271. // }
  272. // else
  273. // {
  274. // if (g_PDKHandle[PDK_PREWATCHDOGACTION] != NULL)
  275. // {
  276. // if( (((int(*)(uint8_t*, WDTTmrMgr_T*, int))g_PDKHandle[PDK_PREWATCHDOGACTION]) (&TmrAction, &g_WDTTmrMgr,BMCInst)) != 0)
  277. // {
  278. // return;
  279. // }
  280. // }
  281. // }
  282. // switch (TmrAction)
  283. // {
  284. // case TIMEOUT_NO_ACTION_TAKEN:
  285. // break;
  286. // case TIMEOUT_ACTION_HARD_RESET:
  287. // //Added for GetSystem RestartCause //
  288. // pBMCInfo->ChassisConfig.SysRestartCause = RESTART_CAUSE_WDT_EXPIRATION;
  289. // //API_OnSetRestartCause(RESTART_CAUSE_WDT_EXPIRATION, TRUE);
  290. // OnSetRestartCause(pBMCInfo->ChassisConfig.SysRestartCause, TRUE,BMCInst);
  291. // // perform the chassis control action
  292. // Platform_HostColdReset (BMCInst);
  293. // break;
  294. // case TIMEOUT_ACTION_POWER_DOWN:
  295. // //Added for GetSystem RestartCause //
  296. // pBMCInfo->ChassisConfig.SysRestartCause = RESTART_CAUSE_WDT_EXPIRATION;
  297. // //API_OnSetRestartCause(RESTART_CAUSE_WDT_EXPIRATION, TRUE);
  298. // OnSetRestartCause(pBMCInfo->ChassisConfig.SysRestartCause, TRUE,BMCInst);
  299. // // perform the chassis control action
  300. // Platform_HostPowerOff (BMCInst);
  301. // break;
  302. // case TIMEOUT_ACTION_POWER_CYCLE:
  303. // //Added for GetSystem RestartCause //
  304. // pBMCInfo->ChassisConfig.SysRestartCause = RESTART_CAUSE_WDT_EXPIRATION;
  305. // //API_OnSetRestartCause(RESTART_CAUSE_WDT_EXPIRATION, TRUE);
  306. // OnSetRestartCause(pBMCInfo->ChassisConfig.SysRestartCause, TRUE,BMCInst);
  307. // // perform the chassis control action
  308. // Platform_HostPowerCycle (BMCInst);
  309. // break;
  310. // case PRE_TIMEOUT_NMI_DIAG:
  311. // // perform the NMI
  312. // Platform_HostDiagInt (BMCInst);
  313. // // fall through
  314. // case PRE_TIMEOUT_SMI:
  315. // case PRE_TIMEOUT_MESSAGING_INTR:
  316. // // setup sensor event offset to be the timer interrupt (08h)
  317. // u8EventOffset = IPMI_WDT_TIMER_INTERRUPT;
  318. // break;
  319. // default:
  320. // IPMI_ERROR("Invalid Timer Action for watchdog.\n");
  321. // break;
  322. // }
  323. // // save the system restart cause even if there is no change
  324. // FlushIPMI((uint8_t*)&pBMCInfo->ChassisConfig,(uint8_t*)&pBMCInfo->ChassisConfig,pBMCInfo->IPMIConfLoc.ChassisConfigAddr,sizeof(ChassisConfig_T),BMCInst);
  325. // // pass the WDT event offset
  326. // if(g_corefeatures.internal_sensor == ENABLED)
  327. // {
  328. // SetWD2SensorReading((1 << u8EventOffset), g_WDTTmrMgr.WDTTmr.TmrUse,g_WDTTmrMgr.WDTTmr.TmrActions,BMCInst);
  329. //
  330. // /* Get the Sensor Shared Memory */
  331. // pSMSharedMem = ( SensorSharedMem_T*)&pBMCInfo->SensorSharedMem;
  332. // for (i = 0; i < pBMCInfo->SenConfig.ValidSensorCnt; i++)
  333. // {
  334. // /* When the SensorType is WatchDog, calling WD2EventLog here to create EventLog instead through SensorMonitor */
  335. // if(pSMSharedMem->SensorInfo[pBMCInfo->SenConfig.ValidSensorList [i]].SensorTypeCode == SENSOR_TYPE_WATCHDOG2)
  336. // {
  337. // pSensorInfo = (SensorInfo_T*)&pSMSharedMem->SensorInfo[pBMCInfo->SenConfig.ValidSensorList [i]];
  338. // WD2EventLog(pSensorInfo,&readFlags,BMCInst);
  339. // }
  340. // }
  341. // }
  342. // if(g_PDKHandle[PDK_WATCHDOGACTION] != NULL)
  343. // {
  344. // ((void(*)(uint8_t,WDTTmrMgr_T*,int))g_PDKHandle[PDK_WATCHDOGACTION]) (TmrAction,&g_WDTTmrMgr,BMCInst);
  345. // }
  346. // /* Clearing don't log bit after Watchdog timeout */
  347. // g_WDTTmrMgr.WDTTmr.TmrUse &= 0x7F;
  348. //}
  349. /*-----------------------------------------------------------------
  350. * @fn StopWDTTimer
  351. *
  352. * @brief This is provided to stop Watchdog Timer.
  353. *
  354. * @return None.
  355. *-----------------------------------------------------------------*/
  356. void
  357. StopWDTTimer ()
  358. {
  359. printf("StopWDTTimer not implement\r\n");
  360. // BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  361. // g_WDTTmrMgr.TmrPresent = FALSE;
  362. // OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->hWDTSharedMemMutex, WAIT_INFINITE);
  363. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTRunning = FALSE;
  364. // BMC_GET_SHARED_MEM(BMCInst)->IsWDTPresent = FALSE;
  365. // OS_THREAD_MUTEX_RELEASE(&pBMCInfo->hWDTSharedMemMutex);
  366. }