include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / arch / powerpc / platforms / pseries / eeh_event.c
CommitLineData
172ca926
LV
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
ac325acd 21#include <linux/delay.h>
172ca926 22#include <linux/list.h>
8c33fd11 23#include <linux/mutex.h>
172ca926 24#include <linux/pci.h>
5a0e3ad6 25#include <linux/slab.h>
8c33fd11 26#include <linux/workqueue.h>
172ca926 27#include <asm/eeh_event.h>
77bd7415 28#include <asm/ppc-pci.h>
172ca926
LV
29
30/** Overview:
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.
36 */
37
38/* EEH event workqueue setup. */
34af946a 39static DEFINE_SPINLOCK(eeh_eventlist_lock);
172ca926 40LIST_HEAD(eeh_eventlist);
c4028958
DH
41static void eeh_thread_launcher(struct work_struct *);
42DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
172ca926 43
8c33fd11
LV
44/* Serialize reset sequences for a given pci device */
45DEFINE_MUTEX(eeh_event_mutex);
46
172ca926 47/**
8c33fd11 48 * eeh_event_handler - dispatch EEH events.
172ca926 49 * @dummy - unused
8c33fd11
LV
50 *
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.
172ca926
LV
56 */
57static int eeh_event_handler(void * dummy)
58{
59 unsigned long flags;
60 struct eeh_event *event;
ac325acd 61 struct pci_dn *pdn;
172ca926
LV
62
63 daemonize ("eehd");
ac325acd 64 set_current_state(TASK_INTERRUPTIBLE);
172ca926 65
ac325acd
LV
66 spin_lock_irqsave(&eeh_eventlist_lock, flags);
67 event = NULL;
172ca926 68
ac325acd
LV
69 /* Unqueue the event, get ready to process. */
70 if (!list_empty(&eeh_eventlist)) {
71 event = list_entry(eeh_eventlist.next, struct eeh_event, list);
72 list_del(&event->list);
73 }
74 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
77bd7415 75
ac325acd
LV
76 if (event == NULL)
77 return 0;
8c33fd11 78
ac325acd
LV
79 /* Serialize processing of EEH events */
80 mutex_lock(&eeh_event_mutex);
81 eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
172ca926 82
ac325acd 83 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
8d3d50bf 84 eeh_pci_name(event->dev));
8c33fd11 85
ac325acd 86 pdn = handle_eeh_events(event);
172ca926 87
ac325acd
LV
88 eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
89 pci_dev_put(event->dev);
90 kfree(event);
91 mutex_unlock(&eeh_event_mutex);
77bd7415 92
ac325acd
LV
93 /* If there are no new errors after an hour, clear the counter. */
94 if (pdn && pdn->eeh_freeze_count>0) {
95 msleep_interruptible (3600*1000);
96 if (pdn->eeh_freeze_count>0)
97 pdn->eeh_freeze_count--;
172ca926
LV
98 }
99
100 return 0;
101}
102
103/**
104 * eeh_thread_launcher
172ca926
LV
105 * @dummy - unused
106 */
c4028958 107static void eeh_thread_launcher(struct work_struct *dummy)
172ca926
LV
108{
109 if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
110 printk(KERN_ERR "Failed to start EEH daemon\n");
111}
112
113/**
114 * eeh_send_failure_event - generate a PCI error event
115 * @dev pci device
116 *
117 * This routine can be called within an interrupt context;
118 * the actual event will be delivered in a normal context
119 * (from a workqueue).
120 */
121int eeh_send_failure_event (struct device_node *dn,
d0ab95ca 122 struct pci_dev *dev)
172ca926
LV
123{
124 unsigned long flags;
125 struct eeh_event *event;
954a46e2 126 const char *location;
172ca926 127
054d8ff3
LV
128 if (!mem_init_done) {
129 printk(KERN_ERR "EEH: event during early boot not handled\n");
e2eb6392 130 location = of_get_property(dn, "ibm,loc-code", NULL);
054d8ff3
LV
131 printk(KERN_ERR "EEH: device node = %s\n", dn->full_name);
132 printk(KERN_ERR "EEH: PCI location = %s\n", location);
133 return 1;
134 }
172ca926
LV
135 event = kmalloc(sizeof(*event), GFP_ATOMIC);
136 if (event == NULL) {
137 printk (KERN_ERR "EEH: out of memory, event not handled\n");
138 return 1;
139 }
140
141 if (dev)
142 pci_dev_get(dev);
143
144 event->dn = dn;
145 event->dev = dev;
172ca926
LV
146
147 /* We may or may not be called in an interrupt context */
148 spin_lock_irqsave(&eeh_eventlist_lock, flags);
149 list_add(&event->list, &eeh_eventlist);
150 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
151
152 schedule_work(&eeh_event_wq);
153
154 return 0;
155}
156
157/********************** END OF FILE ******************************/