eeh_event.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. *
  16. * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/list.h>
  20. #include <linux/sched.h>
  21. #include <linux/semaphore.h>
  22. #include <linux/pci.h>
  23. #include <linux/slab.h>
  24. #include <linux/kthread.h>
  25. #include <asm/eeh_event.h>
  26. #include <asm/ppc-pci.h>
  27. /** Overview:
  28. * EEH error states may be detected within exception handlers;
  29. * however, the recovery processing needs to occur asynchronously
  30. * in a normal kernel context and not an interrupt context.
  31. * This pair of routines creates an event and queues it onto a
  32. * work-queue, where a worker thread can drive recovery.
  33. */
  34. static DEFINE_SPINLOCK(eeh_eventlist_lock);
  35. static struct semaphore eeh_eventlist_sem;
  36. LIST_HEAD(eeh_eventlist);
  37. /**
  38. * eeh_event_handler - Dispatch EEH events.
  39. * @dummy - unused
  40. *
  41. * The detection of a frozen slot can occur inside an interrupt,
  42. * where it can be hard to do anything about it. The goal of this
  43. * routine is to pull these detection events out of the context
  44. * of the interrupt handler, and re-dispatch them for processing
  45. * at a later time in a normal context.
  46. */
  47. static int eeh_event_handler(void * dummy)
  48. {
  49. unsigned long flags;
  50. struct eeh_event *event;
  51. struct eeh_pe *pe;
  52. while (!kthread_should_stop()) {
  53. if (down_interruptible(&eeh_eventlist_sem))
  54. break;
  55. /* Fetch EEH event from the queue */
  56. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  57. event = NULL;
  58. if (!list_empty(&eeh_eventlist)) {
  59. event = list_entry(eeh_eventlist.next,
  60. struct eeh_event, list);
  61. list_del(&event->list);
  62. }
  63. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  64. if (!event)
  65. continue;
  66. /* We might have event without binding PE */
  67. pe = event->pe;
  68. if (pe) {
  69. eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
  70. pr_info("EEH: Detected PCI bus error on PHB#%d-PE#%x\n",
  71. pe->phb->global_number, pe->addr);
  72. eeh_handle_event(pe);
  73. eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
  74. } else {
  75. eeh_handle_event(NULL);
  76. }
  77. kfree(event);
  78. }
  79. return 0;
  80. }
  81. /**
  82. * eeh_event_init - Start kernel thread to handle EEH events
  83. *
  84. * This routine is called to start the kernel thread for processing
  85. * EEH event.
  86. */
  87. int eeh_event_init(void)
  88. {
  89. struct task_struct *t;
  90. int ret = 0;
  91. /* Initialize semaphore */
  92. sema_init(&eeh_eventlist_sem, 0);
  93. t = kthread_run(eeh_event_handler, NULL, "eehd");
  94. if (IS_ERR(t)) {
  95. ret = PTR_ERR(t);
  96. pr_err("%s: Failed to start EEH daemon (%d)\n",
  97. __func__, ret);
  98. return ret;
  99. }
  100. return 0;
  101. }
  102. /**
  103. * eeh_send_failure_event - Generate a PCI error event
  104. * @pe: EEH PE
  105. *
  106. * This routine can be called within an interrupt context;
  107. * the actual event will be delivered in a normal context
  108. * (from a workqueue).
  109. */
  110. int eeh_send_failure_event(struct eeh_pe *pe)
  111. {
  112. unsigned long flags;
  113. struct eeh_event *event;
  114. event = kzalloc(sizeof(*event), GFP_ATOMIC);
  115. if (!event) {
  116. pr_err("EEH: out of memory, event not handled\n");
  117. return -ENOMEM;
  118. }
  119. event->pe = pe;
  120. /* We may or may not be called in an interrupt context */
  121. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  122. list_add(&event->list, &eeh_eventlist);
  123. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  124. /* For EEH deamon to knick in */
  125. up(&eeh_eventlist_sem);
  126. return 0;
  127. }
  128. /**
  129. * eeh_remove_event - Remove EEH event from the queue
  130. * @pe: Event binding to the PE
  131. *
  132. * On PowerNV platform, we might have subsequent coming events
  133. * is part of the former one. For that case, those subsequent
  134. * coming events are totally duplicated and unnecessary, thus
  135. * they should be removed.
  136. */
  137. void eeh_remove_event(struct eeh_pe *pe)
  138. {
  139. unsigned long flags;
  140. struct eeh_event *event, *tmp;
  141. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  142. list_for_each_entry_safe(event, tmp, &eeh_eventlist, list) {
  143. /*
  144. * If we don't have valid PE passed in, that means
  145. * we already have event corresponding to dead IOC
  146. * and all events should be purged.
  147. */
  148. if (!pe) {
  149. list_del(&event->list);
  150. kfree(event);
  151. } else if (pe->type & EEH_PE_PHB) {
  152. if (event->pe && event->pe->phb == pe->phb) {
  153. list_del(&event->list);
  154. kfree(event);
  155. }
  156. } else if (event->pe == pe) {
  157. list_del(&event->list);
  158. kfree(event);
  159. }
  160. }
  161. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  162. }