ras.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. * Copyright (C) 2001 Dave Engebretsen IBM Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/sched.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irq.h>
  21. #include <linux/of.h>
  22. #include <linux/fs.h>
  23. #include <linux/reboot.h>
  24. #include <asm/machdep.h>
  25. #include <asm/rtas.h>
  26. #include <asm/firmware.h>
  27. #include "pseries.h"
  28. static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
  29. static DEFINE_SPINLOCK(ras_log_buf_lock);
  30. static char global_mce_data_buf[RTAS_ERROR_LOG_MAX];
  31. static DEFINE_PER_CPU(__u64, mce_data_buf);
  32. static int ras_check_exception_token;
  33. #define EPOW_SENSOR_TOKEN 9
  34. #define EPOW_SENSOR_INDEX 0
  35. static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
  36. static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
  37. /*
  38. * Initialize handlers for the set of interrupts caused by hardware errors
  39. * and power system events.
  40. */
  41. static int __init init_ras_IRQ(void)
  42. {
  43. struct device_node *np;
  44. ras_check_exception_token = rtas_token("check-exception");
  45. /* Internal Errors */
  46. np = of_find_node_by_path("/event-sources/internal-errors");
  47. if (np != NULL) {
  48. request_event_sources_irqs(np, ras_error_interrupt,
  49. "RAS_ERROR");
  50. of_node_put(np);
  51. }
  52. /* EPOW Events */
  53. np = of_find_node_by_path("/event-sources/epow-events");
  54. if (np != NULL) {
  55. request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
  56. of_node_put(np);
  57. }
  58. return 0;
  59. }
  60. subsys_initcall(init_ras_IRQ);
  61. #define EPOW_SHUTDOWN_NORMAL 1
  62. #define EPOW_SHUTDOWN_ON_UPS 2
  63. #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3
  64. #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4
  65. static void handle_system_shutdown(char event_modifier)
  66. {
  67. switch (event_modifier) {
  68. case EPOW_SHUTDOWN_NORMAL:
  69. pr_emerg("Firmware initiated power off");
  70. orderly_poweroff(1);
  71. break;
  72. case EPOW_SHUTDOWN_ON_UPS:
  73. pr_emerg("Loss of power reported by firmware, system is "
  74. "running on UPS/battery");
  75. break;
  76. case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS:
  77. pr_emerg("Loss of system critical functions reported by "
  78. "firmware");
  79. pr_emerg("Check RTAS error log for details");
  80. orderly_poweroff(1);
  81. break;
  82. case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH:
  83. pr_emerg("Ambient temperature too high reported by firmware");
  84. pr_emerg("Check RTAS error log for details");
  85. orderly_poweroff(1);
  86. break;
  87. default:
  88. pr_err("Unknown power/cooling shutdown event (modifier %d)",
  89. event_modifier);
  90. }
  91. }
  92. struct epow_errorlog {
  93. unsigned char sensor_value;
  94. unsigned char event_modifier;
  95. unsigned char extended_modifier;
  96. unsigned char reserved;
  97. unsigned char platform_reason;
  98. };
  99. #define EPOW_RESET 0
  100. #define EPOW_WARN_COOLING 1
  101. #define EPOW_WARN_POWER 2
  102. #define EPOW_SYSTEM_SHUTDOWN 3
  103. #define EPOW_SYSTEM_HALT 4
  104. #define EPOW_MAIN_ENCLOSURE 5
  105. #define EPOW_POWER_OFF 7
  106. void rtas_parse_epow_errlog(struct rtas_error_log *log)
  107. {
  108. struct pseries_errorlog *pseries_log;
  109. struct epow_errorlog *epow_log;
  110. char action_code;
  111. char modifier;
  112. pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW);
  113. if (pseries_log == NULL)
  114. return;
  115. epow_log = (struct epow_errorlog *)pseries_log->data;
  116. action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */
  117. modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */
  118. switch (action_code) {
  119. case EPOW_RESET:
  120. pr_err("Non critical power or cooling issue cleared");
  121. break;
  122. case EPOW_WARN_COOLING:
  123. pr_err("Non critical cooling issue reported by firmware");
  124. pr_err("Check RTAS error log for details");
  125. break;
  126. case EPOW_WARN_POWER:
  127. pr_err("Non critical power issue reported by firmware");
  128. pr_err("Check RTAS error log for details");
  129. break;
  130. case EPOW_SYSTEM_SHUTDOWN:
  131. handle_system_shutdown(epow_log->event_modifier);
  132. break;
  133. case EPOW_SYSTEM_HALT:
  134. pr_emerg("Firmware initiated power off");
  135. orderly_poweroff(1);
  136. break;
  137. case EPOW_MAIN_ENCLOSURE:
  138. case EPOW_POWER_OFF:
  139. pr_emerg("Critical power/cooling issue reported by firmware");
  140. pr_emerg("Check RTAS error log for details");
  141. pr_emerg("Immediate power off");
  142. emergency_sync();
  143. kernel_power_off();
  144. break;
  145. default:
  146. pr_err("Unknown power/cooling event (action code %d)",
  147. action_code);
  148. }
  149. }
  150. /* Handle environmental and power warning (EPOW) interrupts. */
  151. static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
  152. {
  153. int status;
  154. int state;
  155. int critical;
  156. status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
  157. &state);
  158. if (state > 3)
  159. critical = 1; /* Time Critical */
  160. else
  161. critical = 0;
  162. spin_lock(&ras_log_buf_lock);
  163. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  164. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  165. virq_to_hw(irq),
  166. RTAS_EPOW_WARNING,
  167. critical, __pa(&ras_log_buf),
  168. rtas_get_error_log_max());
  169. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
  170. rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
  171. spin_unlock(&ras_log_buf_lock);
  172. return IRQ_HANDLED;
  173. }
  174. /*
  175. * Handle hardware error interrupts.
  176. *
  177. * RTAS check-exception is called to collect data on the exception. If
  178. * the error is deemed recoverable, we log a warning and return.
  179. * For nonrecoverable errors, an error is logged and we stop all processing
  180. * as quickly as possible in order to prevent propagation of the failure.
  181. */
  182. static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
  183. {
  184. struct rtas_error_log *rtas_elog;
  185. int status;
  186. int fatal;
  187. spin_lock(&ras_log_buf_lock);
  188. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  189. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  190. virq_to_hw(irq),
  191. RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
  192. __pa(&ras_log_buf),
  193. rtas_get_error_log_max());
  194. rtas_elog = (struct rtas_error_log *)ras_log_buf;
  195. if ((status == 0) && (rtas_elog->severity >= RTAS_SEVERITY_ERROR_SYNC))
  196. fatal = 1;
  197. else
  198. fatal = 0;
  199. /* format and print the extended information */
  200. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
  201. if (fatal) {
  202. pr_emerg("Fatal hardware error reported by firmware");
  203. pr_emerg("Check RTAS error log for details");
  204. pr_emerg("Immediate power off");
  205. emergency_sync();
  206. kernel_power_off();
  207. } else {
  208. pr_err("Recoverable hardware error reported by firmware");
  209. }
  210. spin_unlock(&ras_log_buf_lock);
  211. return IRQ_HANDLED;
  212. }
  213. /*
  214. * Some versions of FWNMI place the buffer inside the 4kB page starting at
  215. * 0x7000. Other versions place it inside the rtas buffer. We check both.
  216. */
  217. #define VALID_FWNMI_BUFFER(A) \
  218. ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
  219. (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
  220. /*
  221. * Get the error information for errors coming through the
  222. * FWNMI vectors. The pt_regs' r3 will be updated to reflect
  223. * the actual r3 if possible, and a ptr to the error log entry
  224. * will be returned if found.
  225. *
  226. * If the RTAS error is not of the extended type, then we put it in a per
  227. * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf.
  228. *
  229. * The global_mce_data_buf does not have any locks or protection around it,
  230. * if a second machine check comes in, or a system reset is done
  231. * before we have logged the error, then we will get corruption in the
  232. * error log. This is preferable over holding off on calling
  233. * ibm,nmi-interlock which would result in us checkstopping if a
  234. * second machine check did come in.
  235. */
  236. static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
  237. {
  238. unsigned long *savep;
  239. struct rtas_error_log *h, *errhdr = NULL;
  240. if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
  241. printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
  242. return NULL;
  243. }
  244. savep = __va(regs->gpr[3]);
  245. regs->gpr[3] = savep[0]; /* restore original r3 */
  246. /* If it isn't an extended log we can use the per cpu 64bit buffer */
  247. h = (struct rtas_error_log *)&savep[1];
  248. if (!h->extended) {
  249. memcpy(&__get_cpu_var(mce_data_buf), h, sizeof(__u64));
  250. errhdr = (struct rtas_error_log *)&__get_cpu_var(mce_data_buf);
  251. } else {
  252. int len;
  253. len = max_t(int, 8+h->extended_log_length, RTAS_ERROR_LOG_MAX);
  254. memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
  255. memcpy(global_mce_data_buf, h, len);
  256. errhdr = (struct rtas_error_log *)global_mce_data_buf;
  257. }
  258. return errhdr;
  259. }
  260. /* Call this when done with the data returned by FWNMI_get_errinfo.
  261. * It will release the saved data area for other CPUs in the
  262. * partition to receive FWNMI errors.
  263. */
  264. static void fwnmi_release_errinfo(void)
  265. {
  266. int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
  267. if (ret != 0)
  268. printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
  269. }
  270. int pSeries_system_reset_exception(struct pt_regs *regs)
  271. {
  272. if (fwnmi_active) {
  273. struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
  274. if (errhdr) {
  275. /* XXX Should look at FWNMI information */
  276. }
  277. fwnmi_release_errinfo();
  278. }
  279. return 0; /* need to perform reset */
  280. }
  281. /*
  282. * See if we can recover from a machine check exception.
  283. * This is only called on power4 (or above) and only via
  284. * the Firmware Non-Maskable Interrupts (fwnmi) handler
  285. * which provides the error analysis for us.
  286. *
  287. * Return 1 if corrected (or delivered a signal).
  288. * Return 0 if there is nothing we can do.
  289. */
  290. static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
  291. {
  292. int recovered = 0;
  293. if (!(regs->msr & MSR_RI)) {
  294. /* If MSR_RI isn't set, we cannot recover */
  295. recovered = 0;
  296. } else if (err->disposition == RTAS_DISP_FULLY_RECOVERED) {
  297. /* Platform corrected itself */
  298. recovered = 1;
  299. } else if (err->disposition == RTAS_DISP_LIMITED_RECOVERY) {
  300. /* Platform corrected itself but could be degraded */
  301. printk(KERN_ERR "MCE: limited recovery, system may "
  302. "be degraded\n");
  303. recovered = 1;
  304. } else if (user_mode(regs) && !is_global_init(current) &&
  305. err->severity == RTAS_SEVERITY_ERROR_SYNC) {
  306. /*
  307. * If we received a synchronous error when in userspace
  308. * kill the task. Firmware may report details of the fail
  309. * asynchronously, so we can't rely on the target and type
  310. * fields being valid here.
  311. */
  312. printk(KERN_ERR "MCE: uncorrectable error, killing task "
  313. "%s:%d\n", current->comm, current->pid);
  314. _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
  315. recovered = 1;
  316. }
  317. log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
  318. return recovered;
  319. }
  320. /*
  321. * Handle a machine check.
  322. *
  323. * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
  324. * should be present. If so the handler which called us tells us if the
  325. * error was recovered (never true if RI=0).
  326. *
  327. * On hardware prior to Power 4 these exceptions were asynchronous which
  328. * means we can't tell exactly where it occurred and so we can't recover.
  329. */
  330. int pSeries_machine_check_exception(struct pt_regs *regs)
  331. {
  332. struct rtas_error_log *errp;
  333. if (fwnmi_active) {
  334. errp = fwnmi_get_errinfo(regs);
  335. fwnmi_release_errinfo();
  336. if (errp && recover_mce(regs, errp))
  337. return 1;
  338. }
  339. return 0;
  340. }