blob: ba7005a5e2feb3e810a9fe2588568bb4517407ac [file] [log] [blame]
Linas Vepstas172ca922005-11-03 18:50:04 -06001/*
Linas Vepstas172ca922005-11-03 18:50:04 -06002 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
17 */
18
Linas Vepstasac325ac2006-04-18 21:05:21 -070019#include <linux/delay.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060020#include <linux/list.h>
Linas Vepstas8c33fd112006-03-29 15:29:18 -060021#include <linux/mutex.h>
Paul Gortmaker62fe91b2011-05-27 14:25:11 -040022#include <linux/sched.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060023#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Linas Vepstas8c33fd112006-03-29 15:29:18 -060025#include <linux/workqueue.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060026#include <asm/eeh_event.h>
Linas Vepstas77bd7412005-11-03 18:52:49 -060027#include <asm/ppc-pci.h>
Linas Vepstas172ca922005-11-03 18:50:04 -060028
29/** Overview:
30 * EEH error states may be detected within exception handlers;
31 * however, the recovery processing needs to occur asynchronously
32 * in a normal kernel context and not an interrupt context.
33 * This pair of routines creates an event and queues it onto a
34 * work-queue, where a worker thread can drive recovery.
35 */
36
37/* EEH event workqueue setup. */
Ingo Molnar34af9462006-06-27 02:53:55 -070038static DEFINE_SPINLOCK(eeh_eventlist_lock);
Linas Vepstas172ca922005-11-03 18:50:04 -060039LIST_HEAD(eeh_eventlist);
David Howellsc4028952006-11-22 14:57:56 +000040static void eeh_thread_launcher(struct work_struct *);
41DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
Linas Vepstas172ca922005-11-03 18:50:04 -060042
Linas Vepstas8c33fd112006-03-29 15:29:18 -060043/* Serialize reset sequences for a given pci device */
44DEFINE_MUTEX(eeh_event_mutex);
45
Linas Vepstas172ca922005-11-03 18:50:04 -060046/**
Gavin Shan29f8bf12012-02-27 20:04:02 +000047 * eeh_event_handler - Dispatch EEH events.
Linas Vepstas172ca922005-11-03 18:50:04 -060048 * @dummy - unused
Linas Vepstas8c33fd112006-03-29 15:29:18 -060049 *
50 * The detection of a frozen slot can occur inside an interrupt,
51 * where it can be hard to do anything about it. The goal of this
52 * routine is to pull these detection events out of the context
53 * of the interrupt handler, and re-dispatch them for processing
54 * at a later time in a normal context.
Linas Vepstas172ca922005-11-03 18:50:04 -060055 */
56static int eeh_event_handler(void * dummy)
57{
58 unsigned long flags;
Gavin Shan40a7cd92012-02-27 20:04:08 +000059 struct eeh_event *event;
Gavin Shan120dc492012-09-07 22:44:18 +000060 struct eeh_pe *pe;
Linas Vepstas172ca922005-11-03 18:50:04 -060061
Oleg Nesterov37ef9bd2012-03-28 12:20:57 +000062 set_task_comm(current, "eehd");
Linas Vepstas172ca922005-11-03 18:50:04 -060063
Linas Vepstasac325ac2006-04-18 21:05:21 -070064 spin_lock_irqsave(&eeh_eventlist_lock, flags);
65 event = NULL;
Linas Vepstas172ca922005-11-03 18:50:04 -060066
Linas Vepstasac325ac2006-04-18 21:05:21 -070067 /* Unqueue the event, get ready to process. */
68 if (!list_empty(&eeh_eventlist)) {
69 event = list_entry(eeh_eventlist.next, struct eeh_event, list);
70 list_del(&event->list);
71 }
72 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
Linas Vepstas77bd7412005-11-03 18:52:49 -060073
Linas Vepstasac325ac2006-04-18 21:05:21 -070074 if (event == NULL)
75 return 0;
Linas Vepstas8c33fd112006-03-29 15:29:18 -060076
Linas Vepstasac325ac2006-04-18 21:05:21 -070077 /* Serialize processing of EEH events */
78 mutex_lock(&eeh_event_mutex);
Gavin Shan120dc492012-09-07 22:44:18 +000079 pe = event->pe;
80 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
81 pr_info("EEH: Detected PCI bus error on PHB#%d-PE#%x\n",
82 pe->phb->global_number, pe->addr);
Linas Vepstas8c33fd112006-03-29 15:29:18 -060083
Andrew Morton9b218f62012-03-28 12:20:58 +000084 set_current_state(TASK_INTERRUPTIBLE); /* Don't add to load average */
Gavin Shan120dc492012-09-07 22:44:18 +000085 handle_eeh_events(event);
86 eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
Gavin Shan40a7cd92012-02-27 20:04:08 +000087
Linas Vepstasac325ac2006-04-18 21:05:21 -070088 kfree(event);
89 mutex_unlock(&eeh_event_mutex);
Linas Vepstas172ca922005-11-03 18:50:04 -060090
Linas Vepstasac325ac2006-04-18 21:05:21 -070091 /* If there are no new errors after an hour, clear the counter. */
Gavin Shan120dc492012-09-07 22:44:18 +000092 if (pe && pe->freeze_count > 0) {
Gavin Shan29f8bf12012-02-27 20:04:02 +000093 msleep_interruptible(3600*1000);
Gavin Shan120dc492012-09-07 22:44:18 +000094 if (pe->freeze_count > 0)
95 pe->freeze_count--;
Gavin Shan40a7cd92012-02-27 20:04:08 +000096
Linas Vepstas172ca922005-11-03 18:50:04 -060097 }
98
99 return 0;
100}
101
102/**
Gavin Shan29f8bf12012-02-27 20:04:02 +0000103 * eeh_thread_launcher - Start kernel thread to handle EEH events
Linas Vepstas172ca922005-11-03 18:50:04 -0600104 * @dummy - unused
Gavin Shan29f8bf12012-02-27 20:04:02 +0000105 *
106 * This routine is called to start the kernel thread for processing
107 * EEH event.
Linas Vepstas172ca922005-11-03 18:50:04 -0600108 */
David Howellsc4028952006-11-22 14:57:56 +0000109static void eeh_thread_launcher(struct work_struct *dummy)
Linas Vepstas172ca922005-11-03 18:50:04 -0600110{
111 if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
112 printk(KERN_ERR "Failed to start EEH daemon\n");
113}
114
115/**
Gavin Shan29f8bf12012-02-27 20:04:02 +0000116 * eeh_send_failure_event - Generate a PCI error event
Gavin Shanc533b462012-09-07 22:44:11 +0000117 * @pe: EEH PE
Linas Vepstas172ca922005-11-03 18:50:04 -0600118 *
119 * This routine can be called within an interrupt context;
120 * the actual event will be delivered in a normal context
121 * (from a workqueue).
122 */
Gavin Shanc533b462012-09-07 22:44:11 +0000123int eeh_send_failure_event(struct eeh_pe *pe)
Linas Vepstas172ca922005-11-03 18:50:04 -0600124{
125 unsigned long flags;
126 struct eeh_event *event;
127
Gavin Shan7e4bbaf2012-09-07 22:44:03 +0000128 event = kzalloc(sizeof(*event), GFP_ATOMIC);
Gavin Shanc533b462012-09-07 22:44:11 +0000129 if (!event) {
130 pr_err("EEH: out of memory, event not handled\n");
131 return -ENOMEM;
132 }
133 event->pe = pe;
Linas Vepstas172ca922005-11-03 18:50:04 -0600134
135 /* We may or may not be called in an interrupt context */
136 spin_lock_irqsave(&eeh_eventlist_lock, flags);
137 list_add(&event->list, &eeh_eventlist);
138 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
139
140 schedule_work(&eeh_event_wq);
141
142 return 0;
143}