2005-11-03 17:50:04 -07:00
|
|
|
/*
|
|
|
|
* eeh_event.c
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Linas Vepstas <linas@linas.org>
|
|
|
|
*/
|
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
#include <linux/delay.h>
|
2005-11-03 17:50:04 -07:00
|
|
|
#include <linux/list.h>
|
2006-03-29 14:29:18 -07:00
|
|
|
#include <linux/mutex.h>
|
2005-11-03 17:50:04 -07:00
|
|
|
#include <linux/pci.h>
|
2006-03-29 14:29:18 -07:00
|
|
|
#include <linux/workqueue.h>
|
2005-11-03 17:50:04 -07:00
|
|
|
#include <asm/eeh_event.h>
|
2005-11-03 17:52:49 -07:00
|
|
|
#include <asm/ppc-pci.h>
|
2005-11-03 17:50:04 -07:00
|
|
|
|
|
|
|
/** Overview:
|
|
|
|
* EEH error states may be detected within exception handlers;
|
|
|
|
* however, the recovery processing needs to occur asynchronously
|
|
|
|
* in a normal kernel context and not an interrupt context.
|
|
|
|
* This pair of routines creates an event and queues it onto a
|
|
|
|
* work-queue, where a worker thread can drive recovery.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* EEH event workqueue setup. */
|
2006-06-27 03:53:55 -06:00
|
|
|
static DEFINE_SPINLOCK(eeh_eventlist_lock);
|
2005-11-03 17:50:04 -07:00
|
|
|
LIST_HEAD(eeh_eventlist);
|
2006-11-22 07:57:56 -07:00
|
|
|
static void eeh_thread_launcher(struct work_struct *);
|
|
|
|
DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
|
2005-11-03 17:50:04 -07:00
|
|
|
|
2006-03-29 14:29:18 -07:00
|
|
|
/* Serialize reset sequences for a given pci device */
|
|
|
|
DEFINE_MUTEX(eeh_event_mutex);
|
|
|
|
|
2005-11-03 17:50:04 -07:00
|
|
|
/**
|
2006-03-29 14:29:18 -07:00
|
|
|
* eeh_event_handler - dispatch EEH events.
|
2005-11-03 17:50:04 -07:00
|
|
|
* @dummy - unused
|
2006-03-29 14:29:18 -07:00
|
|
|
*
|
|
|
|
* The detection of a frozen slot can occur inside an interrupt,
|
|
|
|
* where it can be hard to do anything about it. The goal of this
|
|
|
|
* routine is to pull these detection events out of the context
|
|
|
|
* of the interrupt handler, and re-dispatch them for processing
|
|
|
|
* at a later time in a normal context.
|
2005-11-03 17:50:04 -07:00
|
|
|
*/
|
|
|
|
static int eeh_event_handler(void * dummy)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct eeh_event *event;
|
2006-04-18 22:05:21 -06:00
|
|
|
struct pci_dn *pdn;
|
2005-11-03 17:50:04 -07:00
|
|
|
|
|
|
|
daemonize ("eehd");
|
2006-04-18 22:05:21 -06:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2005-11-03 17:50:04 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
spin_lock_irqsave(&eeh_eventlist_lock, flags);
|
|
|
|
event = NULL;
|
2005-11-03 17:50:04 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
/* Unqueue the event, get ready to process. */
|
|
|
|
if (!list_empty(&eeh_eventlist)) {
|
|
|
|
event = list_entry(eeh_eventlist.next, struct eeh_event, list);
|
|
|
|
list_del(&event->list);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
|
2005-11-03 17:52:49 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
if (event == NULL)
|
|
|
|
return 0;
|
2006-03-29 14:29:18 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
/* Serialize processing of EEH events */
|
|
|
|
mutex_lock(&eeh_event_mutex);
|
|
|
|
eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);
|
2005-11-03 17:50:04 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",
|
2010-02-02 22:56:41 -07:00
|
|
|
eeh_pci_name(event->dev));
|
2006-03-29 14:29:18 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
pdn = handle_eeh_events(event);
|
2005-11-03 17:50:04 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);
|
|
|
|
pci_dev_put(event->dev);
|
|
|
|
kfree(event);
|
|
|
|
mutex_unlock(&eeh_event_mutex);
|
2005-11-03 17:52:49 -07:00
|
|
|
|
2006-04-18 22:05:21 -06:00
|
|
|
/* If there are no new errors after an hour, clear the counter. */
|
|
|
|
if (pdn && pdn->eeh_freeze_count>0) {
|
|
|
|
msleep_interruptible (3600*1000);
|
|
|
|
if (pdn->eeh_freeze_count>0)
|
|
|
|
pdn->eeh_freeze_count--;
|
2005-11-03 17:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_thread_launcher
|
|
|
|
* @dummy - unused
|
|
|
|
*/
|
2006-11-22 07:57:56 -07:00
|
|
|
static void eeh_thread_launcher(struct work_struct *dummy)
|
2005-11-03 17:50:04 -07:00
|
|
|
{
|
|
|
|
if (kernel_thread(eeh_event_handler, NULL, CLONE_KERNEL) < 0)
|
|
|
|
printk(KERN_ERR "Failed to start EEH daemon\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_send_failure_event - generate a PCI error event
|
|
|
|
* @dev pci device
|
|
|
|
*
|
|
|
|
* This routine can be called within an interrupt context;
|
|
|
|
* the actual event will be delivered in a normal context
|
|
|
|
* (from a workqueue).
|
|
|
|
*/
|
|
|
|
int eeh_send_failure_event (struct device_node *dn,
|
2007-03-19 13:59:10 -06:00
|
|
|
struct pci_dev *dev)
|
2005-11-03 17:50:04 -07:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct eeh_event *event;
|
2006-07-11 23:39:43 -06:00
|
|
|
const char *location;
|
2005-11-03 17:50:04 -07:00
|
|
|
|
2006-04-27 03:31:20 -06:00
|
|
|
if (!mem_init_done) {
|
|
|
|
printk(KERN_ERR "EEH: event during early boot not handled\n");
|
2007-04-03 06:26:41 -06:00
|
|
|
location = of_get_property(dn, "ibm,loc-code", NULL);
|
2006-04-27 03:31:20 -06:00
|
|
|
printk(KERN_ERR "EEH: device node = %s\n", dn->full_name);
|
|
|
|
printk(KERN_ERR "EEH: PCI location = %s\n", location);
|
|
|
|
return 1;
|
|
|
|
}
|
2005-11-03 17:50:04 -07:00
|
|
|
event = kmalloc(sizeof(*event), GFP_ATOMIC);
|
|
|
|
if (event == NULL) {
|
|
|
|
printk (KERN_ERR "EEH: out of memory, event not handled\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev)
|
|
|
|
pci_dev_get(dev);
|
|
|
|
|
|
|
|
event->dn = dn;
|
|
|
|
event->dev = dev;
|
|
|
|
|
|
|
|
/* We may or may not be called in an interrupt context */
|
|
|
|
spin_lock_irqsave(&eeh_eventlist_lock, flags);
|
|
|
|
list_add(&event->list, &eeh_eventlist);
|
|
|
|
spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
|
|
|
|
|
|
|
|
schedule_work(&eeh_event_wq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************** END OF FILE ******************************/
|