ras.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX, &state);
  157. if (state > 3)
  158. critical = 1; /* Time Critical */
  159. else
  160. critical = 0;
  161. spin_lock(&ras_log_buf_lock);
  162. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  163. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  164. virq_to_hw(irq),
  165. RTAS_EPOW_WARNING,
  166. critical, __pa(&ras_log_buf),
  167. rtas_get_error_log_max());
  168. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
  169. rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
  170. spin_unlock(&ras_log_buf_lock);
  171. return IRQ_HANDLED;
  172. }
  173. /*
  174. * Handle hardware error interrupts.
  175. *
  176. * RTAS check-exception is called to collect data on the exception. If
  177. * the error is deemed recoverable, we log a warning and return.
  178. * For nonrecoverable errors, an error is logged and we stop all processing
  179. * as quickly as possible in order to prevent propagation of the failure.
  180. */
  181. static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
  182. {
  183. struct rtas_error_log *rtas_elog;
  184. int status;
  185. int fatal;
  186. spin_lock(&ras_log_buf_lock);
  187. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  188. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  189. virq_to_hw(irq),
  190. RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
  191. __pa(&ras_log_buf),
  192. rtas_get_error_log_max());
  193. rtas_elog = (struct rtas_error_log *)ras_log_buf;
  194. if ((status == 0) && (rtas_elog->severity >= RTAS_SEVERITY_ERROR_SYNC))
  195. fatal = 1;
  196. else
  197. fatal = 0;
  198. /* format and print the extended information */
  199. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
  200. if (fatal) {
  201. pr_emerg("Fatal hardware error reported by firmware");
  202. pr_emerg("Check RTAS error log for details");
  203. pr_emerg("Immediate power off");
  204. emergency_sync();
  205. kernel_power_off();
  206. } else {
  207. pr_err("Recoverable hardware error reported by firmware");
  208. }
  209. spin_unlock(&ras_log_buf_lock);
  210. return IRQ_HANDLED;
  211. }
  212. /*
  213. * Some versions of FWNMI place the buffer inside the 4kB page starting at
  214. * 0x7000. Other versions place it inside the rtas buffer. We check both.
  215. */
  216. #define VALID_FWNMI_BUFFER(A) \
  217. ((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
  218. (((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
  219. /*
  220. * Get the error information for errors coming through the
  221. * FWNMI vectors. The pt_regs' r3 will be updated to reflect
  222. * the actual r3 if possible, and a ptr to the error log entry
  223. * will be returned if found.
  224. *
  225. * If the RTAS error is not of the extended type, then we put it in a per
  226. * cpu 64bit buffer. If it is the extended type we use global_mce_data_buf.
  227. *
  228. * The global_mce_data_buf does not have any locks or protection around it,
  229. * if a second machine check comes in, or a system reset is done
  230. * before we have logged the error, then we will get corruption in the
  231. * error log. This is preferable over holding off on calling
  232. * ibm,nmi-interlock which would result in us checkstopping if a
  233. * second machine check did come in.
  234. */
  235. static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
  236. {
  237. unsigned long *savep;
  238. struct rtas_error_log *h, *errhdr = NULL;
  239. if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
  240. printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
  241. return NULL;
  242. }
  243. savep = __va(regs->gpr[3]);
  244. regs->gpr[3] = savep[0]; /* restore original r3 */
  245. /* If it isn't an extended log we can use the per cpu 64bit buffer */
  246. h = (struct rtas_error_log *)&savep[1];
  247. if (!h->extended) {
  248. memcpy(&__get_cpu_var(mce_data_buf), h, sizeof(__u64));
  249. errhdr = (struct rtas_error_log *)&__get_cpu_var(mce_data_buf);
  250. } else {
  251. int len;
  252. len = max_t(int, 8+h->extended_log_length, RTAS_ERROR_LOG_MAX);
  253. memset(global_mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
  254. memcpy(global_mce_data_buf, h, len);
  255. errhdr = (struct rtas_error_log *)global_mce_data_buf;
  256. }
  257. return errhdr;
  258. }
  259. /* Call this when done with the data returned by FWNMI_get_errinfo.
  260. * It will release the saved data area for other CPUs in the
  261. * partition to receive FWNMI errors.
  262. */
  263. static void fwnmi_release_errinfo(void)
  264. {
  265. int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
  266. if (ret != 0)
  267. printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
  268. }
  269. int pSeries_system_reset_exception(struct pt_regs *regs)
  270. {
  271. if (fwnmi_active) {
  272. struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
  273. if (errhdr) {
  274. /* XXX Should look at FWNMI information */
  275. }
  276. fwnmi_release_errinfo();
  277. }
  278. return 0; /* need to perform reset */
  279. }
  280. /*
  281. * See if we can recover from a machine check exception.
  282. * This is only called on power4 (or above) and only via
  283. * the Firmware Non-Maskable Interrupts (fwnmi) handler
  284. * which provides the error analysis for us.
  285. *
  286. * Return 1 if corrected (or delivered a signal).
  287. * Return 0 if there is nothing we can do.
  288. */
  289. static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
  290. {
  291. int recovered = 0;
  292. if (!(regs->msr & MSR_RI)) {
  293. /* If MSR_RI isn't set, we cannot recover */
  294. recovered = 0;
  295. } else if (err->disposition == RTAS_DISP_FULLY_RECOVERED) {
  296. /* Platform corrected itself */
  297. recovered = 1;
  298. } else if (err->disposition == RTAS_DISP_LIMITED_RECOVERY) {
  299. /* Platform corrected itself but could be degraded */
  300. printk(KERN_ERR "MCE: limited recovery, system may "
  301. "be degraded\n");
  302. recovered = 1;
  303. } else if (user_mode(regs) && !is_global_init(current) &&
  304. err->severity == RTAS_SEVERITY_ERROR_SYNC) {
  305. /*
  306. * If we received a synchronous error when in userspace
  307. * kill the task. Firmware may report details of the fail
  308. * asynchronously, so we can't rely on the target and type
  309. * fields being valid here.
  310. */
  311. printk(KERN_ERR "MCE: uncorrectable error, killing task "
  312. "%s:%d\n", current->comm, current->pid);
  313. _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
  314. recovered = 1;
  315. }
  316. log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
  317. return recovered;
  318. }
  319. /*
  320. * Handle a machine check.
  321. *
  322. * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
  323. * should be present. If so the handler which called us tells us if the
  324. * error was recovered (never true if RI=0).
  325. *
  326. * On hardware prior to Power 4 these exceptions were asynchronous which
  327. * means we can't tell exactly where it occurred and so we can't recover.
  328. */
  329. int pSeries_machine_check_exception(struct pt_regs *regs)
  330. {
  331. struct rtas_error_log *errp;
  332. if (fwnmi_active) {
  333. errp = fwnmi_get_errinfo(regs);
  334. fwnmi_release_errinfo();
  335. if (errp && recover_mce(regs, errp))
  336. return 1;
  337. }
  338. return 0;
  339. }