blob: d2383cfb6dfd34f86b6f8e3d79437f06506c7273 [file] [log] [blame]
Linas Vepstas172ca922005-11-03 18:50:04 -06001/*
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
Linas Vepstasac325ac2006-04-18 21:05:21 -070021#include <linux/delay.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060022#include <linux/list.h>
Linas Vepstas8c33fd112006-03-29 15:29:18 -060023#include <linux/mutex.h>
Paul Gortmaker62fe91b2011-05-27 14:25:11 -040024#include <linux/sched.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060025#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Linas Vepstas8c33fd112006-03-29 15:29:18 -060027#include <linux/workqueue.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060028#include <asm/eeh_event.h>
Linas Vepstas77bd7412005-11-03 18:52:49 -060029#include <asm/ppc-pci.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060030
31/** Overview:
32 * EEH error states may be detected within exception handlers;
33 * however, the recovery processing needs to occur asynchronously
34 * in a normal kernel context and not an interrupt context.
35 * This pair of routines creates an event and queues it onto a
36 * work-queue, where a worker thread can drive recovery.
37 */
38
39/* EEH event workqueue setup. */
Ingo Molnar34af9462006-06-27 02:53:55 -070040static DEFINE_SPINLOCK(eeh_eventlist_lock);
Linas Vepstas172ca922005-11-03 18:50:04 -060041LIST_HEAD(eeh_eventlist);
David Howellsc4028952006-11-22 14:57:56 +000042static void eeh_thread_launcher(struct work_struct *);
43DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
Linas Vepstas172ca922005-11-03 18:50:04 -060044
Linas Vepstas8c33fd112006-03-29 15:29:18 -060045/* Serialize reset sequences for a given pci device */
46DEFINE_MUTEX(eeh_event_mutex);
47
Linas Vepstas172ca922005-11-03 18:50:04 -060048/**
Linas Vepstas8c33fd112006-03-29 15:29:18 -060049 * eeh_event_handler - dispatch EEH events.
Linas Vepstas172ca922005-11-03 18:50:04 -060050 * @dummy - unused
Linas Vepstas8c33fd112006-03-29 15:29:18 -060051 *
52 * The detection of a frozen slot can occur inside an interrupt,
53 * where it can be hard to do anything about it. The goal of this
54 * routine is to pull these detection events out of the context
55 * of the interrupt handler, and re-dispatch them for processing
56 * at a later time in a normal context.
Linas Vepstas172ca922005-11-03 18:50:04 -060057 */
58static int eeh_event_handler(void * dummy)
59{
60 unsigned long flags;
61 struct eeh_event *event;
Linas Vepstasac325ac2006-04-18 21:05:21 -070062 struct pci_dn *pdn;
Linas Vepstas172ca922005-11-03 18:50:04 -060063
64 daemonize ("eehd");
Linas Vepstasac325ac2006-04-18 21:05:21 -070065 set_current_state(TASK_INTERRUPTIBLE);
Linas Vepstas172ca922005-11-03 18:50:04 -060066
Linas Vepstasac325ac2006-04-18 21:05:21 -070067 spin_lock_irqsave(&eeh_eventlist_lock, flags);
68 event = NULL;
Linas Vepstas172ca922005-11-03 18:50:04 -060069
Linas Vepstasac325ac2006-04-18 21:05:21 -070070 /* Unqueue the event, get ready to process. */
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);
Linas Vepstas77bd7412005-11-03 18:52:49 -060076
Linas Vepstasac325ac2006-04-18 21:05:21 -070077 if (event == NULL)
78 return 0;
Linas Vepstas8c33fd112006-03-29 15:29:18 -060079
Linas Vepstasac325ac2006-04-18 21:05:21 -070080 /* Serialize processing of EEH events */
81 mutex_lock(&eeh_event_mutex);
82 eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
Linas Vepstas172ca922005-11-03 18:50:04 -060083
Linas Vepstasac325ac2006-04-18 21:05:21 -070084 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
Breno Leitao8d3d50b2010-02-03 05:56:41 +000085 eeh_pci_name(event->dev));
Linas Vepstas8c33fd112006-03-29 15:29:18 -060086
Linas Vepstasac325ac2006-04-18 21:05:21 -070087 pdn = handle_eeh_events(event);
Linas Vepstas172ca922005-11-03 18:50:04 -060088
Linas Vepstasac325ac2006-04-18 21:05:21 -070089 eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
90 pci_dev_put(event->dev);
91 kfree(event);
92 mutex_unlock(&eeh_event_mutex);
Linas Vepstas172ca922005-11-03 18:50:04 -060093
Linas Vepstasac325ac2006-04-18 21:05:21 -070094 /* If there are no new errors after an hour, clear the counter. */
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--;
Linas Vepstas172ca922005-11-03 18:50:04 -060099 }
100
101 return 0;
102}
103
104/**
105 * eeh_thread_launcher
Linas Vepstas172ca922005-11-03 18:50:04 -0600106 * @dummy - unused
107 */
David Howellsc4028952006-11-22 14:57:56 +0000108static void eeh_thread_launcher(struct work_struct *dummy)
Linas Vepstas172ca922005-11-03 18:50:04 -0600109{
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 * eeh_send_failure_event - generate a PCI error event
116 * @dev pci device
117 *
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).
121 */
122int eeh_send_failure_event (struct device_node *dn,
Linas Vepstasd0ab95c2007-03-19 14:59:10 -0500123 struct pci_dev *dev)
Linas Vepstas172ca922005-11-03 18:50:04 -0600124{
125 unsigned long flags;
126 struct eeh_event *event;
Jeremy Kerr954a46e2006-07-12 15:39:43 +1000127 const char *location;
Linas Vepstas172ca922005-11-03 18:50:04 -0600128
Linas Vepstas054d8ff2006-04-27 02:31:20 -0700129 if (!mem_init_done) {
130 printk(KERN_ERR "EEH: event during early boot not handled\n");
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000131 location = of_get_property(dn, "ibm,loc-code", NULL);
Linas Vepstas054d8ff2006-04-27 02:31:20 -0700132 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 }
Linas Vepstas172ca922005-11-03 18:50:04 -0600136 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;
Linas Vepstas172ca922005-11-03 18:50:04 -0600147
148 /* We may or may not be called in an interrupt context */
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/********************** END OF FILE ******************************/