Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 1 | /* |
| 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 Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 21 | #include <linux/delay.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 22 | #include <linux/list.h> |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 24 | #include <linux/pci.h> |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 25 | #include <linux/workqueue.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 26 | #include <asm/eeh_event.h> |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame] | 27 | #include <asm/ppc-pci.h> |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 28 | |
| 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 Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 38 | static DEFINE_SPINLOCK(eeh_eventlist_lock); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 39 | LIST_HEAD(eeh_eventlist); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 40 | static void eeh_thread_launcher(struct work_struct *); |
| 41 | DECLARE_WORK(eeh_event_wq, eeh_thread_launcher); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 42 | |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 43 | /* Serialize reset sequences for a given pci device */ |
| 44 | DEFINE_MUTEX(eeh_event_mutex); |
| 45 | |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 46 | /** |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 47 | * eeh_event_handler - dispatch EEH events. |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 48 | * @dummy - unused |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 49 | * |
| 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 Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 55 | */ |
| 56 | static int eeh_event_handler(void * dummy) |
| 57 | { |
| 58 | unsigned long flags; |
| 59 | struct eeh_event *event; |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 60 | struct pci_dn *pdn; |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 61 | |
| 62 | daemonize ("eehd"); |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 63 | set_current_state(TASK_INTERRUPTIBLE); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 64 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 65 | spin_lock_irqsave(&eeh_eventlist_lock, flags); |
| 66 | event = NULL; |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 67 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 68 | /* Unqueue the event, get ready to process. */ |
| 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); |
Linas Vepstas | 77bd741 | 2005-11-03 18:52:49 -0600 | [diff] [blame] | 74 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 75 | if (event == NULL) |
| 76 | return 0; |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 77 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 78 | /* Serialize processing of EEH events */ |
| 79 | mutex_lock(&eeh_event_mutex); |
| 80 | eeh_mark_slot(event->dn, EEH_MODE_RECOVERING); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 81 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 82 | printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n", |
| 83 | pci_name(event->dev)); |
Linas Vepstas | 8c33fd1 | 2006-03-29 15:29:18 -0600 | [diff] [blame] | 84 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 85 | pdn = handle_eeh_events(event); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 86 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 87 | eeh_clear_slot(event->dn, EEH_MODE_RECOVERING); |
| 88 | pci_dev_put(event->dev); |
| 89 | kfree(event); |
| 90 | mutex_unlock(&eeh_event_mutex); |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 91 | |
Linas Vepstas | ac325ac | 2006-04-18 21:05:21 -0700 | [diff] [blame] | 92 | /* If there are no new errors after an hour, clear the counter. */ |
| 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--; |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * eeh_thread_launcher |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 104 | * @dummy - unused |
| 105 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 106 | static void eeh_thread_launcher(struct work_struct *dummy) |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 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 | * eeh_send_failure_event - generate a PCI error event |
| 114 | * @dev pci device |
| 115 | * |
| 116 | * This routine can be called within an interrupt context; |
| 117 | * the actual event will be delivered in a normal context |
| 118 | * (from a workqueue). |
| 119 | */ |
| 120 | int eeh_send_failure_event (struct device_node *dn, |
Linas Vepstas | d0ab95c | 2007-03-19 14:59:10 -0500 | [diff] [blame] | 121 | struct pci_dev *dev) |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 122 | { |
| 123 | unsigned long flags; |
| 124 | struct eeh_event *event; |
Jeremy Kerr | 954a46e | 2006-07-12 15:39:43 +1000 | [diff] [blame] | 125 | const char *location; |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 126 | |
Linas Vepstas | 054d8ff | 2006-04-27 02:31:20 -0700 | [diff] [blame] | 127 | if (!mem_init_done) { |
| 128 | printk(KERN_ERR "EEH: event during early boot not handled\n"); |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 129 | location = of_get_property(dn, "ibm,loc-code", NULL); |
Linas Vepstas | 054d8ff | 2006-04-27 02:31:20 -0700 | [diff] [blame] | 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 | } |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 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; |
Linas Vepstas | 172ca92 | 2005-11-03 18:50:04 -0600 | [diff] [blame] | 145 | |
| 146 | /* We may or may not be called in an interrupt context */ |
| 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 | /********************** END OF FILE ******************************/ |