blob: 0aa0110e4b6cffba335116d7cd836d5f2d22e85c [file] [log] [blame]
Roland Dreier3d155f82005-10-27 11:03:38 -07001/*
2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
Roland Dreier3d155f82005-10-27 11:03:38 -070031 */
32
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080033#include <linux/jiffies.h>
34#include <linux/timer.h>
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030035#include <linux/workqueue.h>
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080036
Roland Dreier3d155f82005-10-27 11:03:38 -070037#include "mthca_dev.h"
38
39enum {
40 MTHCA_CATAS_POLL_INTERVAL = 5 * HZ,
41
42 MTHCA_CATAS_TYPE_INTERNAL = 0,
43 MTHCA_CATAS_TYPE_UPLINK = 3,
44 MTHCA_CATAS_TYPE_DDR = 4,
45 MTHCA_CATAS_TYPE_PARITY = 5,
46};
47
48static DEFINE_SPINLOCK(catas_lock);
49
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030050static LIST_HEAD(catas_list);
51static struct workqueue_struct *catas_wq;
52static struct work_struct catas_work;
53
54static int catas_reset_disable;
55module_param_named(catas_reset_disable, catas_reset_disable, int, 0644);
56MODULE_PARM_DESC(catas_reset_disable, "disable reset on catastrophic event if nonzero");
57
David Howellsc4028952006-11-22 14:57:56 +000058static void catas_reset(struct work_struct *work)
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030059{
60 struct mthca_dev *dev, *tmpdev;
61 LIST_HEAD(tlist);
62 int ret;
63
64 mutex_lock(&mthca_device_mutex);
65
66 spin_lock_irq(&catas_lock);
67 list_splice_init(&catas_list, &tlist);
68 spin_unlock_irq(&catas_lock);
69
70 list_for_each_entry_safe(dev, tmpdev, &tlist, catas_err.list) {
Jack Morgensteind6861592009-09-24 11:55:41 -070071 struct pci_dev *pdev = dev->pdev;
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030072 ret = __mthca_restart_one(dev->pdev);
Jack Morgensteind6861592009-09-24 11:55:41 -070073 /* 'dev' now is not valid */
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030074 if (ret)
Jack Morgensteind6861592009-09-24 11:55:41 -070075 printk(KERN_ERR "mthca %s: Reset failed (%d)\n",
76 pci_name(pdev), ret);
77 else {
78 struct mthca_dev *d = pci_get_drvdata(pdev);
79 mthca_dbg(d, "Reset succeeded\n");
80 }
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030081 }
82
83 mutex_unlock(&mthca_device_mutex);
84}
85
Roland Dreier3d155f82005-10-27 11:03:38 -070086static void handle_catas(struct mthca_dev *dev)
87{
88 struct ib_event event;
Jack Morgensteinb3b30f52006-08-15 21:11:18 +030089 unsigned long flags;
Roland Dreier3d155f82005-10-27 11:03:38 -070090 const char *type;
91 int i;
92
93 event.device = &dev->ib_dev;
94 event.event = IB_EVENT_DEVICE_FATAL;
95 event.element.port_num = 0;
Jack Morgensteind8410642009-09-05 20:36:16 -070096 dev->active = false;
Roland Dreier3d155f82005-10-27 11:03:38 -070097
98 ib_dispatch_event(&event);
99
100 switch (swab32(readl(dev->catas_err.map)) >> 24) {
101 case MTHCA_CATAS_TYPE_INTERNAL:
102 type = "internal error";
103 break;
104 case MTHCA_CATAS_TYPE_UPLINK:
105 type = "uplink bus error";
106 break;
107 case MTHCA_CATAS_TYPE_DDR:
108 type = "DDR data error";
109 break;
110 case MTHCA_CATAS_TYPE_PARITY:
111 type = "internal parity error";
112 break;
113 default:
114 type = "unknown error";
115 break;
116 }
117
118 mthca_err(dev, "Catastrophic error detected: %s\n", type);
119 for (i = 0; i < dev->catas_err.size; ++i)
120 mthca_err(dev, " buf[%02x]: %08x\n",
121 i, swab32(readl(dev->catas_err.map + i)));
Jack Morgensteinb3b30f52006-08-15 21:11:18 +0300122
123 if (catas_reset_disable)
124 return;
125
126 spin_lock_irqsave(&catas_lock, flags);
127 list_add(&dev->catas_err.list, &catas_list);
128 queue_work(catas_wq, &catas_work);
129 spin_unlock_irqrestore(&catas_lock, flags);
Roland Dreier3d155f82005-10-27 11:03:38 -0700130}
131
132static void poll_catas(unsigned long dev_ptr)
133{
134 struct mthca_dev *dev = (struct mthca_dev *) dev_ptr;
Roland Dreier3d155f82005-10-27 11:03:38 -0700135 int i;
136
137 for (i = 0; i < dev->catas_err.size; ++i)
138 if (readl(dev->catas_err.map + i)) {
139 handle_catas(dev);
140 return;
141 }
142
Roland Dreier4522e082008-07-14 23:48:52 -0700143 mod_timer(&dev->catas_err.timer,
Roland Dreierc0369252008-07-14 23:48:52 -0700144 round_jiffies(jiffies + MTHCA_CATAS_POLL_INTERVAL));
Roland Dreier3d155f82005-10-27 11:03:38 -0700145}
146
147void mthca_start_catas_poll(struct mthca_dev *dev)
148{
149 unsigned long addr;
150
151 init_timer(&dev->catas_err.timer);
Roland Dreier3d155f82005-10-27 11:03:38 -0700152 dev->catas_err.map = NULL;
153
154 addr = pci_resource_start(dev->pdev, 0) +
155 ((pci_resource_len(dev->pdev, 0) - 1) &
156 dev->catas_err.addr);
157
Roland Dreier3d155f82005-10-27 11:03:38 -0700158 dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4);
159 if (!dev->catas_err.map) {
160 mthca_warn(dev, "couldn't map catastrophic error region "
161 "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4);
Roland Dreier3d155f82005-10-27 11:03:38 -0700162 return;
163 }
164
165 dev->catas_err.timer.data = (unsigned long) dev;
166 dev->catas_err.timer.function = poll_catas;
167 dev->catas_err.timer.expires = jiffies + MTHCA_CATAS_POLL_INTERVAL;
Jack Morgensteinb3b30f52006-08-15 21:11:18 +0300168 INIT_LIST_HEAD(&dev->catas_err.list);
Roland Dreier3d155f82005-10-27 11:03:38 -0700169 add_timer(&dev->catas_err.timer);
170}
171
172void mthca_stop_catas_poll(struct mthca_dev *dev)
173{
Roland Dreier3d155f82005-10-27 11:03:38 -0700174 del_timer_sync(&dev->catas_err.timer);
175
Roland Dreier208dde22008-09-29 21:37:33 -0700176 if (dev->catas_err.map)
Roland Dreier3d155f82005-10-27 11:03:38 -0700177 iounmap(dev->catas_err.map);
Jack Morgensteinb3b30f52006-08-15 21:11:18 +0300178
179 spin_lock_irq(&catas_lock);
180 list_del(&dev->catas_err.list);
181 spin_unlock_irq(&catas_lock);
182}
183
184int __init mthca_catas_init(void)
185{
David Howellsc4028952006-11-22 14:57:56 +0000186 INIT_WORK(&catas_work, catas_reset);
Jack Morgensteinb3b30f52006-08-15 21:11:18 +0300187
188 catas_wq = create_singlethread_workqueue("mthca_catas");
189 if (!catas_wq)
190 return -ENOMEM;
191
192 return 0;
193}
194
195void mthca_catas_cleanup(void)
196{
197 destroy_workqueue(catas_wq);
Roland Dreier3d155f82005-10-27 11:03:38 -0700198}