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