eeh_event.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. static 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. if (pe->type & EEH_PE_PHB)
  71. pr_info("EEH: Detected error on PHB#%d\n",
  72. pe->phb->global_number);
  73. else
  74. pr_info("EEH: Detected PCI bus error on "
  75. "PHB#%d-PE#%x\n",
  76. pe->phb->global_number, pe->addr);
  77. eeh_handle_event(pe);
  78. eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
  79. } else {
  80. eeh_handle_event(NULL);
  81. }
  82. kfree(event);
  83. }
  84. return 0;
  85. }
  86. /**
  87. * eeh_event_init - Start kernel thread to handle EEH events
  88. *
  89. * This routine is called to start the kernel thread for processing
  90. * EEH event.
  91. */
  92. int eeh_event_init(void)
  93. {
  94. struct task_struct *t;
  95. int ret = 0;
  96. /* Initialize semaphore */
  97. sema_init(&eeh_eventlist_sem, 0);
  98. t = kthread_run(eeh_event_handler, NULL, "eehd");
  99. if (IS_ERR(t)) {
  100. ret = PTR_ERR(t);
  101. pr_err("%s: Failed to start EEH daemon (%d)\n",
  102. __func__, ret);
  103. return ret;
  104. }
  105. return 0;
  106. }
  107. /**
  108. * eeh_send_failure_event - Generate a PCI error event
  109. * @pe: EEH PE
  110. *
  111. * This routine can be called within an interrupt context;
  112. * the actual event will be delivered in a normal context
  113. * (from a workqueue).
  114. */
  115. int eeh_send_failure_event(struct eeh_pe *pe)
  116. {
  117. unsigned long flags;
  118. struct eeh_event *event;
  119. event = kzalloc(sizeof(*event), GFP_ATOMIC);
  120. if (!event) {
  121. pr_err("EEH: out of memory, event not handled\n");
  122. return -ENOMEM;
  123. }
  124. event->pe = pe;
  125. /* We may or may not be called in an interrupt context */
  126. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  127. list_add(&event->list, &eeh_eventlist);
  128. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  129. /* For EEH deamon to knick in */
  130. up(&eeh_eventlist_sem);
  131. return 0;
  132. }
  133. /**
  134. * eeh_remove_event - Remove EEH event from the queue
  135. * @pe: Event binding to the PE
  136. * @force: Event will be removed unconditionally
  137. *
  138. * On PowerNV platform, we might have subsequent coming events
  139. * is part of the former one. For that case, those subsequent
  140. * coming events are totally duplicated and unnecessary, thus
  141. * they should be removed.
  142. */
  143. void eeh_remove_event(struct eeh_pe *pe, bool force)
  144. {
  145. unsigned long flags;
  146. struct eeh_event *event, *tmp;
  147. /*
  148. * If we have NULL PE passed in, we have dead IOC
  149. * or we're sure we can report all existing errors
  150. * by the caller.
  151. *
  152. * With "force", the event with associated PE that
  153. * have been isolated, the event won't be removed
  154. * to avoid event lost.
  155. */
  156. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  157. list_for_each_entry_safe(event, tmp, &eeh_eventlist, list) {
  158. if (!force && event->pe &&
  159. (event->pe->state & EEH_PE_ISOLATED))
  160. continue;
  161. if (!pe) {
  162. list_del(&event->list);
  163. kfree(event);
  164. } else if (pe->type & EEH_PE_PHB) {
  165. if (event->pe && event->pe->phb == pe->phb) {
  166. list_del(&event->list);
  167. kfree(event);
  168. }
  169. } else if (event->pe == pe) {
  170. list_del(&event->list);
  171. kfree(event);
  172. }
  173. }
  174. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  175. }