1
2
3
4
5
6
7#include <linux/delay.h>
8#include <linux/list.h>
9#include <linux/sched.h>
10#include <linux/semaphore.h>
11#include <linux/pci.h>
12#include <linux/slab.h>
13#include <linux/kthread.h>
14#include <asm/eeh_event.h>
15#include <asm/ppc-pci.h>
16
17
18
19
20
21
22
23
24
25static DEFINE_SPINLOCK(eeh_eventlist_lock);
26static DECLARE_COMPLETION(eeh_eventlist_event);
27static LIST_HEAD(eeh_eventlist);
28
29
30
31
32
33
34
35
36
37
38
39static int eeh_event_handler(void * dummy)
40{
41 unsigned long flags;
42 struct eeh_event *event;
43
44 while (!kthread_should_stop()) {
45 if (wait_for_completion_interruptible(&eeh_eventlist_event))
46 break;
47
48
49 spin_lock_irqsave(&eeh_eventlist_lock, flags);
50 event = NULL;
51 if (!list_empty(&eeh_eventlist)) {
52 event = list_entry(eeh_eventlist.next,
53 struct eeh_event, list);
54 list_del(&event->list);
55 }
56 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
57 if (!event)
58 continue;
59
60
61 if (event->pe)
62 eeh_handle_normal_event(event->pe);
63 else
64 eeh_handle_special_event();
65
66 kfree(event);
67 }
68
69 return 0;
70}
71
72
73
74
75
76
77
78int eeh_event_init(void)
79{
80 struct task_struct *t;
81 int ret = 0;
82
83 t = kthread_run(eeh_event_handler, NULL, "eehd");
84 if (IS_ERR(t)) {
85 ret = PTR_ERR(t);
86 pr_err("%s: Failed to start EEH daemon (%d)\n",
87 __func__, ret);
88 return ret;
89 }
90
91 return 0;
92}
93
94
95
96
97
98
99
100
101
102int __eeh_send_failure_event(struct eeh_pe *pe)
103{
104 unsigned long flags;
105 struct eeh_event *event;
106
107 event = kzalloc(sizeof(*event), GFP_ATOMIC);
108 if (!event) {
109 pr_err("EEH: out of memory, event not handled\n");
110 return -ENOMEM;
111 }
112 event->pe = pe;
113
114
115
116
117
118
119 if (pe) {
120#ifdef CONFIG_STACKTRACE
121
122
123
124
125 pe->trace_entries = stack_trace_save(pe->stack_trace,
126 ARRAY_SIZE(pe->stack_trace), 0);
127#endif
128
129 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
130 }
131
132
133 spin_lock_irqsave(&eeh_eventlist_lock, flags);
134 list_add(&event->list, &eeh_eventlist);
135 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
136
137
138 complete(&eeh_eventlist_event);
139
140 return 0;
141}
142
143int eeh_send_failure_event(struct eeh_pe *pe)
144{
145
146
147
148
149 if (eeh_debugfs_no_recover) {
150 pr_err("EEH: Event dropped due to no_recover setting\n");
151 return 0;
152 }
153
154 return __eeh_send_failure_event(pe);
155}
156
157
158
159
160
161
162
163
164
165
166
167void eeh_remove_event(struct eeh_pe *pe, bool force)
168{
169 unsigned long flags;
170 struct eeh_event *event, *tmp;
171
172
173
174
175
176
177
178
179
180
181 spin_lock_irqsave(&eeh_eventlist_lock, flags);
182 list_for_each_entry_safe(event, tmp, &eeh_eventlist, list) {
183 if (!force && event->pe &&
184 (event->pe->state & EEH_PE_ISOLATED))
185 continue;
186
187 if (!pe) {
188 list_del(&event->list);
189 kfree(event);
190 } else if (pe->type & EEH_PE_PHB) {
191 if (event->pe && event->pe->phb == pe->phb) {
192 list_del(&event->list);
193 kfree(event);
194 }
195 } else if (event->pe == pe) {
196 list_del(&event->list);
197 kfree(event);
198 }
199 }
200 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
201}
202