Commit | Line | Data |
---|---|---|
3d155f8c RD |
1 | /* |
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. | |
3d155f8c RD |
31 | */ |
32 | ||
8c65b4a6 TS |
33 | #include <linux/jiffies.h> |
34 | #include <linux/timer.h> | |
b3b30f5e | 35 | #include <linux/workqueue.h> |
8c65b4a6 | 36 | |
3d155f8c RD |
37 | #include "mthca_dev.h" |
38 | ||
39 | enum { | |
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 | ||
48 | static DEFINE_SPINLOCK(catas_lock); | |
49 | ||
b3b30f5e JM |
50 | static LIST_HEAD(catas_list); |
51 | static struct workqueue_struct *catas_wq; | |
52 | static struct work_struct catas_work; | |
53 | ||
54 | static int catas_reset_disable; | |
55 | module_param_named(catas_reset_disable, catas_reset_disable, int, 0644); | |
56 | MODULE_PARM_DESC(catas_reset_disable, "disable reset on catastrophic event if nonzero"); | |
57 | ||
c4028958 | 58 | static void catas_reset(struct work_struct *work) |
b3b30f5e JM |
59 | { |
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) { | |
71 | ret = __mthca_restart_one(dev->pdev); | |
72 | if (ret) | |
73 | mthca_err(dev, "Reset failed (%d)\n", ret); | |
74 | else | |
75 | mthca_dbg(dev, "Reset succeeded\n"); | |
76 | } | |
77 | ||
78 | mutex_unlock(&mthca_device_mutex); | |
79 | } | |
80 | ||
3d155f8c RD |
81 | static void handle_catas(struct mthca_dev *dev) |
82 | { | |
83 | struct ib_event event; | |
b3b30f5e | 84 | unsigned long flags; |
3d155f8c RD |
85 | const char *type; |
86 | int i; | |
87 | ||
88 | event.device = &dev->ib_dev; | |
89 | event.event = IB_EVENT_DEVICE_FATAL; | |
90 | event.element.port_num = 0; | |
91 | ||
92 | ib_dispatch_event(&event); | |
93 | ||
94 | switch (swab32(readl(dev->catas_err.map)) >> 24) { | |
95 | case MTHCA_CATAS_TYPE_INTERNAL: | |
96 | type = "internal error"; | |
97 | break; | |
98 | case MTHCA_CATAS_TYPE_UPLINK: | |
99 | type = "uplink bus error"; | |
100 | break; | |
101 | case MTHCA_CATAS_TYPE_DDR: | |
102 | type = "DDR data error"; | |
103 | break; | |
104 | case MTHCA_CATAS_TYPE_PARITY: | |
105 | type = "internal parity error"; | |
106 | break; | |
107 | default: | |
108 | type = "unknown error"; | |
109 | break; | |
110 | } | |
111 | ||
112 | mthca_err(dev, "Catastrophic error detected: %s\n", type); | |
113 | for (i = 0; i < dev->catas_err.size; ++i) | |
114 | mthca_err(dev, " buf[%02x]: %08x\n", | |
115 | i, swab32(readl(dev->catas_err.map + i))); | |
b3b30f5e JM |
116 | |
117 | if (catas_reset_disable) | |
118 | return; | |
119 | ||
120 | spin_lock_irqsave(&catas_lock, flags); | |
121 | list_add(&dev->catas_err.list, &catas_list); | |
122 | queue_work(catas_wq, &catas_work); | |
123 | spin_unlock_irqrestore(&catas_lock, flags); | |
3d155f8c RD |
124 | } |
125 | ||
126 | static void poll_catas(unsigned long dev_ptr) | |
127 | { | |
128 | struct mthca_dev *dev = (struct mthca_dev *) dev_ptr; | |
3d155f8c RD |
129 | int i; |
130 | ||
131 | for (i = 0; i < dev->catas_err.size; ++i) | |
132 | if (readl(dev->catas_err.map + i)) { | |
133 | handle_catas(dev); | |
134 | return; | |
135 | } | |
136 | ||
4522e08c | 137 | mod_timer(&dev->catas_err.timer, |
c036925a | 138 | round_jiffies(jiffies + MTHCA_CATAS_POLL_INTERVAL)); |
3d155f8c RD |
139 | } |
140 | ||
141 | void mthca_start_catas_poll(struct mthca_dev *dev) | |
142 | { | |
143 | unsigned long addr; | |
144 | ||
145 | init_timer(&dev->catas_err.timer); | |
3d155f8c RD |
146 | dev->catas_err.map = NULL; |
147 | ||
148 | addr = pci_resource_start(dev->pdev, 0) + | |
149 | ((pci_resource_len(dev->pdev, 0) - 1) & | |
150 | dev->catas_err.addr); | |
151 | ||
152 | if (!request_mem_region(addr, dev->catas_err.size * 4, | |
153 | DRV_NAME)) { | |
154 | mthca_warn(dev, "couldn't request catastrophic error region " | |
155 | "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4); | |
156 | return; | |
157 | } | |
158 | ||
159 | dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4); | |
160 | if (!dev->catas_err.map) { | |
161 | mthca_warn(dev, "couldn't map catastrophic error region " | |
162 | "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4); | |
163 | release_mem_region(addr, dev->catas_err.size * 4); | |
164 | return; | |
165 | } | |
166 | ||
167 | dev->catas_err.timer.data = (unsigned long) dev; | |
168 | dev->catas_err.timer.function = poll_catas; | |
169 | dev->catas_err.timer.expires = jiffies + MTHCA_CATAS_POLL_INTERVAL; | |
b3b30f5e | 170 | INIT_LIST_HEAD(&dev->catas_err.list); |
3d155f8c RD |
171 | add_timer(&dev->catas_err.timer); |
172 | } | |
173 | ||
174 | void mthca_stop_catas_poll(struct mthca_dev *dev) | |
175 | { | |
3d155f8c RD |
176 | del_timer_sync(&dev->catas_err.timer); |
177 | ||
178 | if (dev->catas_err.map) { | |
179 | iounmap(dev->catas_err.map); | |
180 | release_mem_region(pci_resource_start(dev->pdev, 0) + | |
181 | ((pci_resource_len(dev->pdev, 0) - 1) & | |
182 | dev->catas_err.addr), | |
183 | dev->catas_err.size * 4); | |
184 | } | |
b3b30f5e JM |
185 | |
186 | spin_lock_irq(&catas_lock); | |
187 | list_del(&dev->catas_err.list); | |
188 | spin_unlock_irq(&catas_lock); | |
189 | } | |
190 | ||
191 | int __init mthca_catas_init(void) | |
192 | { | |
c4028958 | 193 | INIT_WORK(&catas_work, catas_reset); |
b3b30f5e JM |
194 | |
195 | catas_wq = create_singlethread_workqueue("mthca_catas"); | |
196 | if (!catas_wq) | |
197 | return -ENOMEM; | |
198 | ||
199 | return 0; | |
200 | } | |
201 | ||
202 | void mthca_catas_cleanup(void) | |
203 | { | |
204 | destroy_workqueue(catas_wq); | |
3d155f8c | 205 | } |