eeh_event.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * eeh_event.c
  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. * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
  19. */
  20. #include <linux/delay.h>
  21. #include <linux/list.h>
  22. #include <linux/mutex.h>
  23. #include <linux/sched.h>
  24. #include <linux/pci.h>
  25. #include <linux/slab.h>
  26. #include <linux/workqueue.h>
  27. #include <asm/eeh_event.h>
  28. #include <asm/ppc-pci.h>
  29. /** Overview:
  30. * EEH error states may be detected within exception handlers;
  31. * however, the recovery processing needs to occur asynchronously
  32. * in a normal kernel context and not an interrupt context.
  33. * This pair of routines creates an event and queues it onto a
  34. * work-queue, where a worker thread can drive recovery.
  35. */
  36. /* EEH event workqueue setup. */
  37. static DEFINE_SPINLOCK(eeh_eventlist_lock);
  38. LIST_HEAD(eeh_eventlist);
  39. static void eeh_thread_launcher(struct work_struct *);
  40. DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
  41. /* Serialize reset sequences for a given pci device */
  42. DEFINE_MUTEX(eeh_event_mutex);
  43. /**
  44. * eeh_event_handler - dispatch EEH events.
  45. * @dummy - unused
  46. *
  47. * The detection of a frozen slot can occur inside an interrupt,
  48. * where it can be hard to do anything about it. The goal of this
  49. * routine is to pull these detection events out of the context
  50. * of the interrupt handler, and re-dispatch them for processing
  51. * at a later time in a normal context.
  52. */
  53. static int eeh_event_handler(void * dummy)
  54. {
  55. unsigned long flags;
  56. struct eeh_event *event;
  57. struct pci_dn *pdn;
  58. daemonize ("eehd");
  59. set_current_state(TASK_INTERRUPTIBLE);
  60. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  61. event = NULL;
  62. /* Unqueue the event, get ready to process. */
  63. if (!list_empty(&eeh_eventlist)) {
  64. event = list_entry(eeh_eventlist.next, struct eeh_event, list);
  65. list_del(&event->list);
  66. }
  67. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  68. if (event == NULL)
  69. return 0;
  70. /* Serialize processing of EEH events */
  71. mutex_lock(&eeh_event_mutex);
  72. eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
  73. printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
  74. eeh_pci_name(event->dev));
  75. pdn = handle_eeh_events(event);
  76. eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
  77. pci_dev_put(event->dev);
  78. kfree(event);
  79. mutex_unlock(&eeh_event_mutex);
  80. /* If there are no new errors after an hour, clear the counter. */
  81. if (pdn && pdn->eeh_freeze_count>0) {
  82. msleep_interruptible (3600*1000);
  83. if (pdn->eeh_freeze_count>0)
  84. pdn->eeh_freeze_count--;
  85. }
  86. return 0;
  87. }
  88. /**
  89. * eeh_thread_launcher
  90. * @dummy - unused
  91. */
  92. static void eeh_thread_launcher(struct work_struct *dummy)
  93. {
  94. if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
  95. printk(KERN_ERR "Failed to start EEH daemon\n");
  96. }
  97. /**
  98. * eeh_send_failure_event - generate a PCI error event
  99. * @dev pci device
  100. *
  101. * This routine can be called within an interrupt context;
  102. * the actual event will be delivered in a normal context
  103. * (from a workqueue).
  104. */
  105. int eeh_send_failure_event (struct device_node *dn,
  106. struct pci_dev *dev)
  107. {
  108. unsigned long flags;
  109. struct eeh_event *event;
  110. const char *location;
  111. if (!mem_init_done) {
  112. printk(KERN_ERR "EEH: event during early boot not handled\n");
  113. location = of_get_property(dn, "ibm,loc-code", NULL);
  114. printk(KERN_ERR "EEH: device node = %s\n", dn->full_name);
  115. printk(KERN_ERR "EEH: PCI location = %s\n", location);
  116. return 1;
  117. }
  118. event = kmalloc(sizeof(*event), GFP_ATOMIC);
  119. if (event == NULL) {
  120. printk (KERN_ERR "EEH: out of memory, event not handled\n");
  121. return 1;
  122. }
  123. if (dev)
  124. pci_dev_get(dev);
  125. event->dn = dn;
  126. event->dev = dev;
  127. /* We may or may not be called in an interrupt context */
  128. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  129. list_add(&event->list, &eeh_eventlist);
  130. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  131. schedule_work(&eeh_event_wq);
  132. return 0;
  133. }
  134. /********************** END OF FILE ******************************/