1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/delay.h>
22#include <linux/list.h>
23#include <linux/mutex.h>
24#include <linux/sched.h>
25#include <linux/pci.h>
26#include <linux/slab.h>
27#include <linux/workqueue.h>
28#include <asm/eeh_event.h>
29#include <asm/ppc-pci.h>
30
31
32
33
34
35
36
37
38
39
40static DEFINE_SPINLOCK(eeh_eventlist_lock);
41LIST_HEAD(eeh_eventlist);
42static void eeh_thread_launcher(struct work_struct *);
43DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
44
45
46DEFINE_MUTEX(eeh_event_mutex);
47
48
49
50
51
52
53
54
55
56
57
58static int eeh_event_handler(void * dummy)
59{
60 unsigned long flags;
61 struct eeh_event *event;
62 struct pci_dn *pdn;
63
64 daemonize ("eehd");
65 set_current_state(TASK_INTERRUPTIBLE);
66
67 spin_lock_irqsave(&eeh_eventlist_lock, flags);
68 event = NULL;
69
70
71 if (!list_empty(&eeh_eventlist)) {
72 event = list_entry(eeh_eventlist.next, struct eeh_event, list);
73 list_del(&event->list);
74 }
75 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
76
77 if (event == NULL)
78 return 0;
79
80
81 mutex_lock(&eeh_event_mutex);
82 eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
83
84 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
85 eeh_pci_name(event->dev));
86
87 pdn = handle_eeh_events(event);
88
89 eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
90 pci_dev_put(event->dev);
91 kfree(event);
92 mutex_unlock(&eeh_event_mutex);
93
94
95 if (pdn && pdn->eeh_freeze_count>0) {
96 msleep_interruptible (3600*1000);
97 if (pdn->eeh_freeze_count>0)
98 pdn->eeh_freeze_count--;
99 }
100
101 return 0;
102}
103
104
105
106
107
108static void eeh_thread_launcher(struct work_struct *dummy)
109{
110 if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
111 printk(KERN_ERR "Failed to start EEH daemon\n");
112}
113
114
115
116
117
118
119
120
121
122int eeh_send_failure_event (struct device_node *dn,
123 struct pci_dev *dev)
124{
125 unsigned long flags;
126 struct eeh_event *event;
127 const char *location;
128
129 if (!mem_init_done) {
130 printk(KERN_ERR "EEH: event during early boot not handled\n");
131 location = of_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);
134 return 1;
135 }
136 event = kmalloc(sizeof(*event), GFP_ATOMIC);
137 if (event == NULL) {
138 printk (KERN_ERR "EEH: out of memory, event not handled\n");
139 return 1;
140 }
141
142 if (dev)
143 pci_dev_get(dev);
144
145 event->dn = dn;
146 event->dev = dev;
147
148
149 spin_lock_irqsave(&eeh_eventlist_lock, flags);
150 list_add(&event->list, &eeh_eventlist);
151 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
152
153 schedule_work(&eeh_event_wq);
154
155 return 0;
156}
157
158
159