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.
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.
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
18 * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
21 #include <linux/delay.h>
22 #include <linux/list.h>
23 #include <linux/mutex.h>
24 #include <linux/pci.h>
25 #include <linux/workqueue.h>
26 #include <asm/eeh_event.h>
27 #include <asm/ppc-pci.h>
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.
37 /* EEH event workqueue setup. */
38 static spinlock_t eeh_eventlist_lock = SPIN_LOCK_UNLOCKED;
39 LIST_HEAD(eeh_eventlist);
40 static void eeh_thread_launcher(void *);
41 DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL);
43 /* Serialize reset sequences for a given pci device */
44 DEFINE_MUTEX(eeh_event_mutex);
47 * eeh_event_handler - dispatch EEH events.
50 * The detection of a frozen slot can occur inside an interrupt,
51 * where it can be hard to do anything about it. The goal of this
52 * routine is to pull these detection events out of the context
53 * of the interrupt handler, and re-dispatch them for processing
54 * at a later time in a normal context.
56 static int eeh_event_handler(void * dummy)
59 struct eeh_event *event;
63 set_current_state(TASK_INTERRUPTIBLE);
65 spin_lock_irqsave(&eeh_eventlist_lock, flags);
68 /* Unqueue the event, get ready to process. */
69 if (!list_empty(&eeh_eventlist)) {
70 event = list_entry(eeh_eventlist.next, struct eeh_event, list);
71 list_del(&event->list);
73 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
78 /* Serialize processing of EEH events */
79 mutex_lock(&eeh_event_mutex);
80 eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
82 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
83 pci_name(event->dev));
85 pdn = handle_eeh_events(event);
87 eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
88 pci_dev_put(event->dev);
90 mutex_unlock(&eeh_event_mutex);
92 /* If there are no new errors after an hour, clear the counter. */
93 if (pdn && pdn->eeh_freeze_count>0) {
94 msleep_interruptible (3600*1000);
95 if (pdn->eeh_freeze_count>0)
96 pdn->eeh_freeze_count--;
103 * eeh_thread_launcher
106 static void eeh_thread_launcher(void *dummy)
108 if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
109 printk(KERN_ERR "Failed to start EEH daemon\n");
113 * eeh_send_failure_event - generate a PCI error event
116 * This routine can be called within an interrupt context;
117 * the actual event will be delivered in a normal context
118 * (from a workqueue).
120 int eeh_send_failure_event (struct device_node *dn,
122 enum pci_channel_state state,
126 struct eeh_event *event;
129 if (!mem_init_done) {
130 printk(KERN_ERR "EEH: event during early boot not handled\n");
131 location = (char *) get_property(dn, "ibm,loc-code", NULL);
132 printk(KERN_ERR "EEH: device node = %s\n", dn->full_name);
133 printk(KERN_ERR "EEH: PCI location = %s\n", location);
136 event = kmalloc(sizeof(*event), GFP_ATOMIC);
138 printk (KERN_ERR "EEH: out of memory, event not handled\n");
147 event->state = state;
148 event->time_unavail = time_unavail;
150 /* We may or may not be called in an interrupt context */
151 spin_lock_irqsave(&eeh_eventlist_lock, flags);
152 list_add(&event->list, &eeh_eventlist);
153 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
155 schedule_work(&eeh_event_wq);
160 /********************** END OF FILE ******************************/