ras.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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 <linux/irq_work.h>
  25. #include <asm/machdep.h>
  26. #include <asm/rtas.h>
  27. #include <asm/firmware.h>
  28. #include "pseries.h"
  29. static unsigned char ras_log_buf[RTAS_ERROR_LOG_MAX];
  30. static DEFINE_SPINLOCK(ras_log_buf_lock);
  31. static int ras_check_exception_token;
  32. static void mce_process_errlog_event(struct irq_work *work);
  33. static struct irq_work mce_errlog_process_work = {
  34. .func = mce_process_errlog_event,
  35. };
  36. #define EPOW_SENSOR_TOKEN 9
  37. #define EPOW_SENSOR_INDEX 0
  38. /* EPOW events counter variable */
  39. static int num_epow_events;
  40. static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id);
  41. static irqreturn_t ras_epow_interrupt(int irq, void *dev_id);
  42. static irqreturn_t ras_error_interrupt(int irq, void *dev_id);
  43. /*
  44. * Enable the hotplug interrupt late because processing them may touch other
  45. * devices or systems (e.g. hugepages) that have not been initialized at the
  46. * subsys stage.
  47. */
  48. int __init init_ras_hotplug_IRQ(void)
  49. {
  50. struct device_node *np;
  51. /* Hotplug Events */
  52. np = of_find_node_by_path("/event-sources/hot-plug-events");
  53. if (np != NULL) {
  54. if (dlpar_workqueue_init() == 0)
  55. request_event_sources_irqs(np, ras_hotplug_interrupt,
  56. "RAS_HOTPLUG");
  57. of_node_put(np);
  58. }
  59. return 0;
  60. }
  61. machine_late_initcall(pseries, init_ras_hotplug_IRQ);
  62. /*
  63. * Initialize handlers for the set of interrupts caused by hardware errors
  64. * and power system events.
  65. */
  66. static int __init init_ras_IRQ(void)
  67. {
  68. struct device_node *np;
  69. ras_check_exception_token = rtas_token("check-exception");
  70. /* Internal Errors */
  71. np = of_find_node_by_path("/event-sources/internal-errors");
  72. if (np != NULL) {
  73. request_event_sources_irqs(np, ras_error_interrupt,
  74. "RAS_ERROR");
  75. of_node_put(np);
  76. }
  77. /* EPOW Events */
  78. np = of_find_node_by_path("/event-sources/epow-events");
  79. if (np != NULL) {
  80. request_event_sources_irqs(np, ras_epow_interrupt, "RAS_EPOW");
  81. of_node_put(np);
  82. }
  83. return 0;
  84. }
  85. machine_subsys_initcall(pseries, init_ras_IRQ);
  86. #define EPOW_SHUTDOWN_NORMAL 1
  87. #define EPOW_SHUTDOWN_ON_UPS 2
  88. #define EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS 3
  89. #define EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH 4
  90. static void handle_system_shutdown(char event_modifier)
  91. {
  92. switch (event_modifier) {
  93. case EPOW_SHUTDOWN_NORMAL:
  94. pr_emerg("Power off requested\n");
  95. orderly_poweroff(true);
  96. break;
  97. case EPOW_SHUTDOWN_ON_UPS:
  98. pr_emerg("Loss of system power detected. System is running on"
  99. " UPS/battery. Check RTAS error log for details\n");
  100. break;
  101. case EPOW_SHUTDOWN_LOSS_OF_CRITICAL_FUNCTIONS:
  102. pr_emerg("Loss of system critical functions detected. Check"
  103. " RTAS error log for details\n");
  104. orderly_poweroff(true);
  105. break;
  106. case EPOW_SHUTDOWN_AMBIENT_TEMPERATURE_TOO_HIGH:
  107. pr_emerg("High ambient temperature detected. Check RTAS"
  108. " error log for details\n");
  109. orderly_poweroff(true);
  110. break;
  111. default:
  112. pr_err("Unknown power/cooling shutdown event (modifier = %d)\n",
  113. event_modifier);
  114. }
  115. }
  116. struct epow_errorlog {
  117. unsigned char sensor_value;
  118. unsigned char event_modifier;
  119. unsigned char extended_modifier;
  120. unsigned char reserved;
  121. unsigned char platform_reason;
  122. };
  123. #define EPOW_RESET 0
  124. #define EPOW_WARN_COOLING 1
  125. #define EPOW_WARN_POWER 2
  126. #define EPOW_SYSTEM_SHUTDOWN 3
  127. #define EPOW_SYSTEM_HALT 4
  128. #define EPOW_MAIN_ENCLOSURE 5
  129. #define EPOW_POWER_OFF 7
  130. static void rtas_parse_epow_errlog(struct rtas_error_log *log)
  131. {
  132. struct pseries_errorlog *pseries_log;
  133. struct epow_errorlog *epow_log;
  134. char action_code;
  135. char modifier;
  136. pseries_log = get_pseries_errorlog(log, PSERIES_ELOG_SECT_ID_EPOW);
  137. if (pseries_log == NULL)
  138. return;
  139. epow_log = (struct epow_errorlog *)pseries_log->data;
  140. action_code = epow_log->sensor_value & 0xF; /* bottom 4 bits */
  141. modifier = epow_log->event_modifier & 0xF; /* bottom 4 bits */
  142. switch (action_code) {
  143. case EPOW_RESET:
  144. if (num_epow_events) {
  145. pr_info("Non critical power/cooling issue cleared\n");
  146. num_epow_events--;
  147. }
  148. break;
  149. case EPOW_WARN_COOLING:
  150. pr_info("Non-critical cooling issue detected. Check RTAS error"
  151. " log for details\n");
  152. break;
  153. case EPOW_WARN_POWER:
  154. pr_info("Non-critical power issue detected. Check RTAS error"
  155. " log for details\n");
  156. break;
  157. case EPOW_SYSTEM_SHUTDOWN:
  158. handle_system_shutdown(epow_log->event_modifier);
  159. break;
  160. case EPOW_SYSTEM_HALT:
  161. pr_emerg("Critical power/cooling issue detected. Check RTAS"
  162. " error log for details. Powering off.\n");
  163. orderly_poweroff(true);
  164. break;
  165. case EPOW_MAIN_ENCLOSURE:
  166. case EPOW_POWER_OFF:
  167. pr_emerg("System about to lose power. Check RTAS error log "
  168. " for details. Powering off immediately.\n");
  169. emergency_sync();
  170. kernel_power_off();
  171. break;
  172. default:
  173. pr_err("Unknown power/cooling event (action code = %d)\n",
  174. action_code);
  175. }
  176. /* Increment epow events counter variable */
  177. if (action_code != EPOW_RESET)
  178. num_epow_events++;
  179. }
  180. static irqreturn_t ras_hotplug_interrupt(int irq, void *dev_id)
  181. {
  182. struct pseries_errorlog *pseries_log;
  183. struct pseries_hp_errorlog *hp_elog;
  184. spin_lock(&ras_log_buf_lock);
  185. rtas_call(ras_check_exception_token, 6, 1, NULL,
  186. RTAS_VECTOR_EXTERNAL_INTERRUPT, virq_to_hw(irq),
  187. RTAS_HOTPLUG_EVENTS, 0, __pa(&ras_log_buf),
  188. rtas_get_error_log_max());
  189. pseries_log = get_pseries_errorlog((struct rtas_error_log *)ras_log_buf,
  190. PSERIES_ELOG_SECT_ID_HOTPLUG);
  191. hp_elog = (struct pseries_hp_errorlog *)pseries_log->data;
  192. /*
  193. * Since PCI hotplug is not currently supported on pseries, put PCI
  194. * hotplug events on the ras_log_buf to be handled by rtas_errd.
  195. */
  196. if (hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_MEM ||
  197. hp_elog->resource == PSERIES_HP_ELOG_RESOURCE_CPU)
  198. queue_hotplug_event(hp_elog, NULL, NULL);
  199. else
  200. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
  201. spin_unlock(&ras_log_buf_lock);
  202. return IRQ_HANDLED;
  203. }
  204. /* Handle environmental and power warning (EPOW) interrupts. */
  205. static irqreturn_t ras_epow_interrupt(int irq, void *dev_id)
  206. {
  207. int status;
  208. int state;
  209. int critical;
  210. status = rtas_get_sensor_fast(EPOW_SENSOR_TOKEN, EPOW_SENSOR_INDEX,
  211. &state);
  212. if (state > 3)
  213. critical = 1; /* Time Critical */
  214. else
  215. critical = 0;
  216. spin_lock(&ras_log_buf_lock);
  217. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  218. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  219. virq_to_hw(irq),
  220. RTAS_EPOW_WARNING,
  221. critical, __pa(&ras_log_buf),
  222. rtas_get_error_log_max());
  223. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, 0);
  224. rtas_parse_epow_errlog((struct rtas_error_log *)ras_log_buf);
  225. spin_unlock(&ras_log_buf_lock);
  226. return IRQ_HANDLED;
  227. }
  228. /*
  229. * Handle hardware error interrupts.
  230. *
  231. * RTAS check-exception is called to collect data on the exception. If
  232. * the error is deemed recoverable, we log a warning and return.
  233. * For nonrecoverable errors, an error is logged and we stop all processing
  234. * as quickly as possible in order to prevent propagation of the failure.
  235. */
  236. static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
  237. {
  238. struct rtas_error_log *rtas_elog;
  239. int status;
  240. int fatal;
  241. spin_lock(&ras_log_buf_lock);
  242. status = rtas_call(ras_check_exception_token, 6, 1, NULL,
  243. RTAS_VECTOR_EXTERNAL_INTERRUPT,
  244. virq_to_hw(irq),
  245. RTAS_INTERNAL_ERROR, 1 /* Time Critical */,
  246. __pa(&ras_log_buf),
  247. rtas_get_error_log_max());
  248. rtas_elog = (struct rtas_error_log *)ras_log_buf;
  249. if (status == 0 &&
  250. rtas_error_severity(rtas_elog) >= RTAS_SEVERITY_ERROR_SYNC)
  251. fatal = 1;
  252. else
  253. fatal = 0;
  254. /* format and print the extended information */
  255. log_error(ras_log_buf, ERR_TYPE_RTAS_LOG, fatal);
  256. if (fatal) {
  257. pr_emerg("Fatal hardware error detected. Check RTAS error"
  258. " log for details. Powering off immediately\n");
  259. emergency_sync();
  260. kernel_power_off();
  261. } else {
  262. pr_err("Recoverable hardware error detected\n");
  263. }
  264. spin_unlock(&ras_log_buf_lock);
  265. return IRQ_HANDLED;
  266. }
  267. /*
  268. * Some versions of FWNMI place the buffer inside the 4kB page starting at
  269. * 0x7000. Other versions place it inside the rtas buffer. We check both.
  270. * Minimum size of the buffer is 16 bytes.
  271. */
  272. #define VALID_FWNMI_BUFFER(A) \
  273. ((((A) >= 0x7000) && ((A) <= 0x8000 - 16)) || \
  274. (((A) >= rtas.base) && ((A) <= (rtas.base + rtas.size - 16))))
  275. static inline struct rtas_error_log *fwnmi_get_errlog(void)
  276. {
  277. return (struct rtas_error_log *)local_paca->mce_data_buf;
  278. }
  279. /*
  280. * Get the error information for errors coming through the
  281. * FWNMI vectors. The pt_regs' r3 will be updated to reflect
  282. * the actual r3 if possible, and a ptr to the error log entry
  283. * will be returned if found.
  284. *
  285. * Use one buffer mce_data_buf per cpu to store RTAS error.
  286. *
  287. * The mce_data_buf does not have any locks or protection around it,
  288. * if a second machine check comes in, or a system reset is done
  289. * before we have logged the error, then we will get corruption in the
  290. * error log. This is preferable over holding off on calling
  291. * ibm,nmi-interlock which would result in us checkstopping if a
  292. * second machine check did come in.
  293. */
  294. static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
  295. {
  296. unsigned long *savep;
  297. struct rtas_error_log *h;
  298. /* Mask top two bits */
  299. regs->gpr[3] &= ~(0x3UL << 62);
  300. if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
  301. printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
  302. return NULL;
  303. }
  304. savep = __va(regs->gpr[3]);
  305. regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */
  306. h = (struct rtas_error_log *)&savep[1];
  307. /* Use the per cpu buffer from paca to store rtas error log */
  308. memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
  309. if (!rtas_error_extended(h)) {
  310. memcpy(local_paca->mce_data_buf, h, sizeof(__u64));
  311. } else {
  312. int len, error_log_length;
  313. error_log_length = 8 + rtas_error_extended_log_length(h);
  314. len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
  315. memcpy(local_paca->mce_data_buf, h, len);
  316. }
  317. return (struct rtas_error_log *)local_paca->mce_data_buf;
  318. }
  319. /* Call this when done with the data returned by FWNMI_get_errinfo.
  320. * It will release the saved data area for other CPUs in the
  321. * partition to receive FWNMI errors.
  322. */
  323. static void fwnmi_release_errinfo(void)
  324. {
  325. int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
  326. if (ret != 0)
  327. printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
  328. }
  329. int pSeries_system_reset_exception(struct pt_regs *regs)
  330. {
  331. #ifdef __LITTLE_ENDIAN__
  332. /*
  333. * Some firmware byteswaps SRR registers and gives incorrect SRR1. Try
  334. * to detect the bad SRR1 pattern here. Flip the NIP back to correct
  335. * endian for reporting purposes. Unfortunately the MSR can't be fixed,
  336. * so clear it. It will be missing MSR_RI so we won't try to recover.
  337. */
  338. if ((be64_to_cpu(regs->msr) &
  339. (MSR_LE|MSR_RI|MSR_DR|MSR_IR|MSR_ME|MSR_PR|
  340. MSR_ILE|MSR_HV|MSR_SF)) == (MSR_DR|MSR_SF)) {
  341. regs->nip = be64_to_cpu((__be64)regs->nip);
  342. regs->msr = 0;
  343. }
  344. #endif
  345. if (fwnmi_active) {
  346. struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
  347. if (errhdr) {
  348. /* XXX Should look at FWNMI information */
  349. }
  350. fwnmi_release_errinfo();
  351. }
  352. if (smp_handle_nmi_ipi(regs))
  353. return 1;
  354. return 0; /* need to perform reset */
  355. }
  356. /*
  357. * Process MCE rtas errlog event.
  358. */
  359. static void mce_process_errlog_event(struct irq_work *work)
  360. {
  361. struct rtas_error_log *err;
  362. err = fwnmi_get_errlog();
  363. log_error((char *)err, ERR_TYPE_RTAS_LOG, 0);
  364. }
  365. /*
  366. * See if we can recover from a machine check exception.
  367. * This is only called on power4 (or above) and only via
  368. * the Firmware Non-Maskable Interrupts (fwnmi) handler
  369. * which provides the error analysis for us.
  370. *
  371. * Return 1 if corrected (or delivered a signal).
  372. * Return 0 if there is nothing we can do.
  373. */
  374. static int recover_mce(struct pt_regs *regs, struct rtas_error_log *err)
  375. {
  376. int recovered = 0;
  377. int disposition = rtas_error_disposition(err);
  378. if (!(regs->msr & MSR_RI)) {
  379. /* If MSR_RI isn't set, we cannot recover */
  380. recovered = 0;
  381. } else if (disposition == RTAS_DISP_FULLY_RECOVERED) {
  382. /* Platform corrected itself */
  383. recovered = 1;
  384. } else if (disposition == RTAS_DISP_LIMITED_RECOVERY) {
  385. /* Platform corrected itself but could be degraded */
  386. printk(KERN_ERR "MCE: limited recovery, system may "
  387. "be degraded\n");
  388. recovered = 1;
  389. } else if (user_mode(regs) && !is_global_init(current) &&
  390. rtas_error_severity(err) == RTAS_SEVERITY_ERROR_SYNC) {
  391. /*
  392. * If we received a synchronous error when in userspace
  393. * kill the task. Firmware may report details of the fail
  394. * asynchronously, so we can't rely on the target and type
  395. * fields being valid here.
  396. */
  397. printk(KERN_ERR "MCE: uncorrectable error, killing task "
  398. "%s:%d\n", current->comm, current->pid);
  399. _exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
  400. recovered = 1;
  401. }
  402. /* Queue irq work to log this rtas event later. */
  403. irq_work_queue(&mce_errlog_process_work);
  404. return recovered;
  405. }
  406. /*
  407. * Handle a machine check.
  408. *
  409. * Note that on Power 4 and beyond Firmware Non-Maskable Interrupts (fwnmi)
  410. * should be present. If so the handler which called us tells us if the
  411. * error was recovered (never true if RI=0).
  412. *
  413. * On hardware prior to Power 4 these exceptions were asynchronous which
  414. * means we can't tell exactly where it occurred and so we can't recover.
  415. */
  416. int pSeries_machine_check_exception(struct pt_regs *regs)
  417. {
  418. struct rtas_error_log *errp;
  419. if (fwnmi_active) {
  420. errp = fwnmi_get_errinfo(regs);
  421. fwnmi_release_errinfo();
  422. if (errp && recover_mce(regs, errp))
  423. return 1;
  424. }
  425. return 0;
  426. }