eeh_event.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/list.h>
  21. #include <linux/pci.h>
  22. #include <asm/eeh_event.h>
  23. /** Overview:
  24. * EEH error states may be detected within exception handlers;
  25. * however, the recovery processing needs to occur asynchronously
  26. * in a normal kernel context and not an interrupt context.
  27. * This pair of routines creates an event and queues it onto a
  28. * work-queue, where a worker thread can drive recovery.
  29. */
  30. /* EEH event workqueue setup. */
  31. static spinlock_t eeh_eventlist_lock = SPIN_LOCK_UNLOCKED;
  32. LIST_HEAD(eeh_eventlist);
  33. static void eeh_thread_launcher(void *);
  34. DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL);
  35. /**
  36. * eeh_panic - call panic() for an eeh event that cannot be handled.
  37. * The philosophy of this routine is that it is better to panic and
  38. * halt the OS than it is to risk possible data corruption by
  39. * oblivious device drivers that don't know better.
  40. *
  41. * @dev pci device that had an eeh event
  42. * @reset_state current reset state of the device slot
  43. */
  44. static void eeh_panic(struct pci_dev *dev, int reset_state)
  45. {
  46. /*
  47. * Since the panic_on_oops sysctl is used to halt the system
  48. * in light of potential corruption, we can use it here.
  49. */
  50. if (panic_on_oops) {
  51. panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,
  52. pci_name(dev));
  53. }
  54. else {
  55. printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",
  56. reset_state, pci_name(dev));
  57. }
  58. }
  59. /**
  60. * eeh_event_handler - dispatch EEH events. The detection of a frozen
  61. * slot can occur inside an interrupt, where it can be hard to do
  62. * anything about it. The goal of this routine is to pull these
  63. * detection events out of the context of the interrupt handler, and
  64. * re-dispatch them for processing at a later time in a normal context.
  65. *
  66. * @dummy - unused
  67. */
  68. static int eeh_event_handler(void * dummy)
  69. {
  70. unsigned long flags;
  71. struct eeh_event *event;
  72. daemonize ("eehd");
  73. while (1) {
  74. set_current_state(TASK_INTERRUPTIBLE);
  75. spin_lock_irqsave(&eeh_eventlist_lock, flags);
  76. event = NULL;
  77. if (!list_empty(&eeh_eventlist)) {
  78. event = list_entry(eeh_eventlist.next, struct eeh_event, list);
  79. list_del(&event->list);
  80. }
  81. spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
  82. if (event == NULL)
  83. break;
  84. printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
  85. pci_name(event->dev));
  86. eeh_panic (event->dev, event->state);
  87. kfree(event);
  88. }
  89. return 0;
  90. }
  91. /**
  92. * eeh_thread_launcher
  93. *
  94. * @dummy - unused
  95. */
  96. static void eeh_thread_launcher(void *dummy)
  97. {
  98. if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
  99. printk(KERN_ERR "Failed to start EEH daemon\n");
  100. }
  101. /**
  102. * eeh_send_failure_event - generate a PCI error event
  103. * @dev pci device
  104. *
  105. * This routine can be called within an interrupt context;
  106. * the actual event will be delivered in a normal context
  107. * (from a workqueue).
  108. */
  109. int eeh_send_failure_event (struct device_node *dn,
  110. struct pci_dev *dev,
  111. int state,
  112. int time_unavail)
  113. {
  114. unsigned long flags;
  115. struct eeh_event *event;
  116. event = kmalloc(sizeof(*event), GFP_ATOMIC);
  117. if (event == NULL) {
  118. printk (KERN_ERR "EEH: out of memory, event not handled\n");
  119. return 1;
  120. }
  121. if (dev)
  122. pci_dev_get(dev);
  123. event->dn = dn;
  124. event->dev = dev;
  125. event->state = state;
  126. event->time_unavail = time_unavail;
  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 ******************************/