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.
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.
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
16 * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
19 #include <linux/delay.h>
20 #include <linux/list.h>
21 #include <linux/mutex.h>
22 #include <linux/sched.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/workqueue.h>
26 #include <linux/kthread.h>
27 #include <asm/eeh_event.h>
28 #include <asm/ppc-pci.h>
31 * EEH error states may be detected within exception handlers;
32 * however, the recovery processing needs to occur asynchronously
33 * in a normal kernel context and not an interrupt context.
34 * This pair of routines creates an event and queues it onto a
35 * work-queue, where a worker thread can drive recovery.
38 /* EEH event workqueue setup. */
39 static DEFINE_SPINLOCK(eeh_eventlist_lock
);
40 LIST_HEAD(eeh_eventlist
);
41 static void eeh_thread_launcher(struct work_struct
*);
42 DECLARE_WORK(eeh_event_wq
, eeh_thread_launcher
);
44 /* Serialize reset sequences for a given pci device */
45 DEFINE_MUTEX(eeh_event_mutex
);
48 * eeh_event_handler - Dispatch EEH events.
51 * The detection of a frozen slot can occur inside an interrupt,
52 * where it can be hard to do anything about it. The goal of this
53 * routine is to pull these detection events out of the context
54 * of the interrupt handler, and re-dispatch them for processing
55 * at a later time in a normal context.
57 static int eeh_event_handler(void * dummy
)
60 struct eeh_event
*event
;
63 spin_lock_irqsave(&eeh_eventlist_lock
, flags
);
66 /* Unqueue the event, get ready to process. */
67 if (!list_empty(&eeh_eventlist
)) {
68 event
= list_entry(eeh_eventlist
.next
, struct eeh_event
, list
);
69 list_del(&event
->list
);
71 spin_unlock_irqrestore(&eeh_eventlist_lock
, flags
);
76 /* Serialize processing of EEH events */
77 mutex_lock(&eeh_event_mutex
);
79 eeh_pe_state_mark(pe
, EEH_PE_RECOVERING
);
80 pr_info("EEH: Detected PCI bus error on PHB#%d-PE#%x\n",
81 pe
->phb
->global_number
, pe
->addr
);
83 set_current_state(TASK_INTERRUPTIBLE
); /* Don't add to load average */
85 eeh_pe_state_clear(pe
, EEH_PE_RECOVERING
);
88 mutex_unlock(&eeh_event_mutex
);
90 /* If there are no new errors after an hour, clear the counter. */
91 if (pe
&& pe
->freeze_count
> 0) {
92 msleep_interruptible(3600*1000);
93 if (pe
->freeze_count
> 0)
102 * eeh_thread_launcher - Start kernel thread to handle EEH events
105 * This routine is called to start the kernel thread for processing
108 static void eeh_thread_launcher(struct work_struct
*dummy
)
110 if (IS_ERR(kthread_run(eeh_event_handler
, NULL
, "eehd")))
111 printk(KERN_ERR
"Failed to start EEH daemon\n");
115 * eeh_send_failure_event - Generate a PCI error event
118 * This routine can be called within an interrupt context;
119 * the actual event will be delivered in a normal context
120 * (from a workqueue).
122 int eeh_send_failure_event(struct eeh_pe
*pe
)
125 struct eeh_event
*event
;
127 event
= kzalloc(sizeof(*event
), GFP_ATOMIC
);
129 pr_err("EEH: out of memory, event not handled\n");
134 /* We may or may not be called in an interrupt context */
135 spin_lock_irqsave(&eeh_eventlist_lock
, flags
);
136 list_add(&event
->list
, &eeh_eventlist
);
137 spin_unlock_irqrestore(&eeh_eventlist_lock
, flags
);
139 schedule_work(&eeh_event_wq
);