Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 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 | |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <asm/eeh_event.h> |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame^] | 24 | #include <asm/ppc-pci.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 25 | |
| 26 | /** Overview: |
| 27 | * EEH error states may be detected within exception handlers; |
| 28 | * however, the recovery processing needs to occur asynchronously |
| 29 | * in a normal kernel context and not an interrupt context. |
| 30 | * This pair of routines creates an event and queues it onto a |
| 31 | * work-queue, where a worker thread can drive recovery. |
| 32 | */ |
| 33 | |
| 34 | /* EEH event workqueue setup. */ |
| 35 | static spinlock_t eeh_eventlist_lock = SPIN_LOCK_UNLOCKED; |
| 36 | LIST_HEAD(eeh_eventlist); |
| 37 | static void eeh_thread_launcher(void *); |
| 38 | DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL); |
| 39 | |
| 40 | /** |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 41 | * eeh_event_handler - dispatch EEH events. The detection of a frozen |
| 42 | * slot can occur inside an interrupt, where it can be hard to do |
| 43 | * anything about it. The goal of this routine is to pull these |
| 44 | * detection events out of the context of the interrupt handler, and |
| 45 | * re-dispatch them for processing at a later time in a normal context. |
| 46 | * |
| 47 | * @dummy - unused |
| 48 | */ |
| 49 | static int eeh_event_handler(void * dummy) |
| 50 | { |
| 51 | unsigned long flags; |
| 52 | struct eeh_event *event; |
| 53 | |
| 54 | daemonize ("eehd"); |
| 55 | |
| 56 | while (1) { |
| 57 | set_current_state(TASK_INTERRUPTIBLE); |
| 58 | |
| 59 | spin_lock_irqsave(&eeh_eventlist_lock, flags); |
| 60 | event = NULL; |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame^] | 61 | |
| 62 | /* Unqueue the event, get ready to process. */ |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 63 | if (!list_empty(&eeh_eventlist)) { |
| 64 | event = list_entry(eeh_eventlist.next, struct eeh_event, list); |
| 65 | list_del(&event->list); |
| 66 | } |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame^] | 67 | |
| 68 | if (event) |
| 69 | eeh_mark_slot(event->dn, EEH_MODE_RECOVERING); |
| 70 | |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 71 | spin_unlock_irqrestore(&eeh_eventlist_lock, flags); |
| 72 | if (event == NULL) |
| 73 | break; |
| 74 | |
| 75 | printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n", |
| 76 | pci_name(event->dev)); |
| 77 | |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame^] | 78 | handle_eeh_events(event); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 79 | |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame^] | 80 | eeh_clear_slot(event->dn, EEH_MODE_RECOVERING); |
| 81 | |
| 82 | pci_dev_put(event->dev); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 83 | kfree(event); |
| 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * eeh_thread_launcher |
| 91 | * |
| 92 | * @dummy - unused |
| 93 | */ |
| 94 | static void eeh_thread_launcher(void *dummy) |
| 95 | { |
| 96 | if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0) |
| 97 | printk(KERN_ERR "Failed to start EEH daemon\n"); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * eeh_send_failure_event - generate a PCI error event |
| 102 | * @dev pci device |
| 103 | * |
| 104 | * This routine can be called within an interrupt context; |
| 105 | * the actual event will be delivered in a normal context |
| 106 | * (from a workqueue). |
| 107 | */ |
| 108 | int eeh_send_failure_event (struct device_node *dn, |
| 109 | struct pci_dev *dev, |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame^] | 110 | enum pci_channel_state state, |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 111 | int time_unavail) |
| 112 | { |
| 113 | unsigned long flags; |
| 114 | struct eeh_event *event; |
| 115 | |
| 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 | |
| 122 | if (dev) |
| 123 | pci_dev_get(dev); |
| 124 | |
| 125 | event->dn = dn; |
| 126 | event->dev = dev; |
| 127 | event->state = state; |
| 128 | event->time_unavail = time_unavail; |
| 129 | |
| 130 | /* We may or may not be called in an interrupt context */ |
| 131 | spin_lock_irqsave(&eeh_eventlist_lock, flags); |
| 132 | list_add(&event->list, &eeh_eventlist); |
| 133 | spin_unlock_irqrestore(&eeh_eventlist_lock, flags); |
| 134 | |
| 135 | schedule_work(&eeh_event_wq); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /********************** END OF FILE ******************************/ |