xref: /openbmc/linux/drivers/infiniband/hw/mthca/mthca_catas.c (revision 664b0bae0b87f69bc9deb098f5e0158b9cf18e04)
13d155f8cSRoland Dreier /*
23d155f8cSRoland Dreier  * Copyright (c) 2005 Cisco Systems.  All rights reserved.
33d155f8cSRoland Dreier  *
43d155f8cSRoland Dreier  * This software is available to you under a choice of one of two
53d155f8cSRoland Dreier  * licenses.  You may choose to be licensed under the terms of the GNU
63d155f8cSRoland Dreier  * General Public License (GPL) Version 2, available from the file
73d155f8cSRoland Dreier  * COPYING in the main directory of this source tree, or the
83d155f8cSRoland Dreier  * OpenIB.org BSD license below:
93d155f8cSRoland Dreier  *
103d155f8cSRoland Dreier  *     Redistribution and use in source and binary forms, with or
113d155f8cSRoland Dreier  *     without modification, are permitted provided that the following
123d155f8cSRoland Dreier  *     conditions are met:
133d155f8cSRoland Dreier  *
143d155f8cSRoland Dreier  *      - Redistributions of source code must retain the above
153d155f8cSRoland Dreier  *        copyright notice, this list of conditions and the following
163d155f8cSRoland Dreier  *        disclaimer.
173d155f8cSRoland Dreier  *
183d155f8cSRoland Dreier  *      - Redistributions in binary form must reproduce the above
193d155f8cSRoland Dreier  *        copyright notice, this list of conditions and the following
203d155f8cSRoland Dreier  *        disclaimer in the documentation and/or other materials
213d155f8cSRoland Dreier  *        provided with the distribution.
223d155f8cSRoland Dreier  *
233d155f8cSRoland Dreier  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
243d155f8cSRoland Dreier  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
253d155f8cSRoland Dreier  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
263d155f8cSRoland Dreier  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
273d155f8cSRoland Dreier  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
283d155f8cSRoland Dreier  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
293d155f8cSRoland Dreier  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
303d155f8cSRoland Dreier  * SOFTWARE.
313d155f8cSRoland Dreier  */
323d155f8cSRoland Dreier 
338c65b4a6STim Schmielau #include <linux/jiffies.h>
34e4dd23d7SPaul Gortmaker #include <linux/module.h>
358c65b4a6STim Schmielau #include <linux/timer.h>
36b3b30f5eSJack Morgenstein #include <linux/workqueue.h>
378c65b4a6STim Schmielau 
383d155f8cSRoland Dreier #include "mthca_dev.h"
393d155f8cSRoland Dreier 
403d155f8cSRoland Dreier enum {
413d155f8cSRoland Dreier 	MTHCA_CATAS_POLL_INTERVAL	= 5 * HZ,
423d155f8cSRoland Dreier 
433d155f8cSRoland Dreier 	MTHCA_CATAS_TYPE_INTERNAL	= 0,
443d155f8cSRoland Dreier 	MTHCA_CATAS_TYPE_UPLINK		= 3,
453d155f8cSRoland Dreier 	MTHCA_CATAS_TYPE_DDR		= 4,
463d155f8cSRoland Dreier 	MTHCA_CATAS_TYPE_PARITY		= 5,
473d155f8cSRoland Dreier };
483d155f8cSRoland Dreier 
493d155f8cSRoland Dreier static DEFINE_SPINLOCK(catas_lock);
503d155f8cSRoland Dreier 
51b3b30f5eSJack Morgenstein static LIST_HEAD(catas_list);
52b3b30f5eSJack Morgenstein static struct workqueue_struct *catas_wq;
53b3b30f5eSJack Morgenstein static struct work_struct catas_work;
54b3b30f5eSJack Morgenstein 
55b3b30f5eSJack Morgenstein static int catas_reset_disable;
56b3b30f5eSJack Morgenstein module_param_named(catas_reset_disable, catas_reset_disable, int, 0644);
57b3b30f5eSJack Morgenstein MODULE_PARM_DESC(catas_reset_disable, "disable reset on catastrophic event if nonzero");
58b3b30f5eSJack Morgenstein 
catas_reset(struct work_struct * work)59c4028958SDavid Howells static void catas_reset(struct work_struct *work)
60b3b30f5eSJack Morgenstein {
61b3b30f5eSJack Morgenstein 	struct mthca_dev *dev, *tmpdev;
62b3b30f5eSJack Morgenstein 	LIST_HEAD(tlist);
63b3b30f5eSJack Morgenstein 	int ret;
64b3b30f5eSJack Morgenstein 
65b3b30f5eSJack Morgenstein 	mutex_lock(&mthca_device_mutex);
66b3b30f5eSJack Morgenstein 
67b3b30f5eSJack Morgenstein 	spin_lock_irq(&catas_lock);
68b3b30f5eSJack Morgenstein 	list_splice_init(&catas_list, &tlist);
69b3b30f5eSJack Morgenstein 	spin_unlock_irq(&catas_lock);
70b3b30f5eSJack Morgenstein 
71b3b30f5eSJack Morgenstein 	list_for_each_entry_safe(dev, tmpdev, &tlist, catas_err.list) {
72d686159eSJack Morgenstein 		struct pci_dev *pdev = dev->pdev;
73b3b30f5eSJack Morgenstein 		ret = __mthca_restart_one(dev->pdev);
74d686159eSJack Morgenstein 		/* 'dev' now is not valid */
75b3b30f5eSJack Morgenstein 		if (ret)
76d686159eSJack Morgenstein 			printk(KERN_ERR "mthca %s: Reset failed (%d)\n",
77d686159eSJack Morgenstein 			       pci_name(pdev), ret);
78d686159eSJack Morgenstein 		else {
79d686159eSJack Morgenstein 			struct mthca_dev *d = pci_get_drvdata(pdev);
80d686159eSJack Morgenstein 			mthca_dbg(d, "Reset succeeded\n");
81d686159eSJack Morgenstein 		}
82b3b30f5eSJack Morgenstein 	}
83b3b30f5eSJack Morgenstein 
84b3b30f5eSJack Morgenstein 	mutex_unlock(&mthca_device_mutex);
85b3b30f5eSJack Morgenstein }
86b3b30f5eSJack Morgenstein 
handle_catas(struct mthca_dev * dev)873d155f8cSRoland Dreier static void handle_catas(struct mthca_dev *dev)
883d155f8cSRoland Dreier {
893d155f8cSRoland Dreier 	struct ib_event event;
90b3b30f5eSJack Morgenstein 	unsigned long flags;
913d155f8cSRoland Dreier 	const char *type;
923d155f8cSRoland Dreier 	int i;
933d155f8cSRoland Dreier 
943d155f8cSRoland Dreier 	event.device = &dev->ib_dev;
953d155f8cSRoland Dreier 	event.event  = IB_EVENT_DEVICE_FATAL;
963d155f8cSRoland Dreier 	event.element.port_num = 0;
97d8410647SJack Morgenstein 	dev->active = false;
983d155f8cSRoland Dreier 
993d155f8cSRoland Dreier 	ib_dispatch_event(&event);
1003d155f8cSRoland Dreier 
1013d155f8cSRoland Dreier 	switch (swab32(readl(dev->catas_err.map)) >> 24) {
1023d155f8cSRoland Dreier 	case MTHCA_CATAS_TYPE_INTERNAL:
1033d155f8cSRoland Dreier 		type = "internal error";
1043d155f8cSRoland Dreier 		break;
1053d155f8cSRoland Dreier 	case MTHCA_CATAS_TYPE_UPLINK:
1063d155f8cSRoland Dreier 		type = "uplink bus error";
1073d155f8cSRoland Dreier 		break;
1083d155f8cSRoland Dreier 	case MTHCA_CATAS_TYPE_DDR:
1093d155f8cSRoland Dreier 		type = "DDR data error";
1103d155f8cSRoland Dreier 		break;
1113d155f8cSRoland Dreier 	case MTHCA_CATAS_TYPE_PARITY:
1123d155f8cSRoland Dreier 		type = "internal parity error";
1133d155f8cSRoland Dreier 		break;
1143d155f8cSRoland Dreier 	default:
1153d155f8cSRoland Dreier 		type = "unknown error";
1163d155f8cSRoland Dreier 		break;
1173d155f8cSRoland Dreier 	}
1183d155f8cSRoland Dreier 
1193d155f8cSRoland Dreier 	mthca_err(dev, "Catastrophic error detected: %s\n", type);
1203d155f8cSRoland Dreier 	for (i = 0; i < dev->catas_err.size; ++i)
1213d155f8cSRoland Dreier 		mthca_err(dev, "  buf[%02x]: %08x\n",
1223d155f8cSRoland Dreier 			  i, swab32(readl(dev->catas_err.map + i)));
123b3b30f5eSJack Morgenstein 
124b3b30f5eSJack Morgenstein 	if (catas_reset_disable)
125b3b30f5eSJack Morgenstein 		return;
126b3b30f5eSJack Morgenstein 
127b3b30f5eSJack Morgenstein 	spin_lock_irqsave(&catas_lock, flags);
128b3b30f5eSJack Morgenstein 	list_add(&dev->catas_err.list, &catas_list);
129b3b30f5eSJack Morgenstein 	queue_work(catas_wq, &catas_work);
130b3b30f5eSJack Morgenstein 	spin_unlock_irqrestore(&catas_lock, flags);
1313d155f8cSRoland Dreier }
1323d155f8cSRoland Dreier 
poll_catas(struct timer_list * t)133*86cb30ecSKees Cook static void poll_catas(struct timer_list *t)
1343d155f8cSRoland Dreier {
135*86cb30ecSKees Cook 	struct mthca_dev *dev = from_timer(dev, t, catas_err.timer);
1363d155f8cSRoland Dreier 	int i;
1373d155f8cSRoland Dreier 
1383d155f8cSRoland Dreier 	for (i = 0; i < dev->catas_err.size; ++i)
1393d155f8cSRoland Dreier 		if (readl(dev->catas_err.map + i)) {
1403d155f8cSRoland Dreier 			handle_catas(dev);
1413d155f8cSRoland Dreier 			return;
1423d155f8cSRoland Dreier 		}
1433d155f8cSRoland Dreier 
1443d155f8cSRoland Dreier 	mod_timer(&dev->catas_err.timer,
145c036925aSRoland Dreier 		  round_jiffies(jiffies + MTHCA_CATAS_POLL_INTERVAL));
1463d155f8cSRoland Dreier }
1473d155f8cSRoland Dreier 
mthca_start_catas_poll(struct mthca_dev * dev)1483d155f8cSRoland Dreier void mthca_start_catas_poll(struct mthca_dev *dev)
1493d155f8cSRoland Dreier {
150eb4a7cbfSJohn L. Burr 	phys_addr_t addr;
1513d155f8cSRoland Dreier 
152*86cb30ecSKees Cook 	timer_setup(&dev->catas_err.timer, poll_catas, 0);
1533d155f8cSRoland Dreier 	dev->catas_err.map  = NULL;
1543d155f8cSRoland Dreier 
1553d155f8cSRoland Dreier 	addr = pci_resource_start(dev->pdev, 0) +
1563d155f8cSRoland Dreier 		((pci_resource_len(dev->pdev, 0) - 1) &
1573d155f8cSRoland Dreier 		 dev->catas_err.addr);
1583d155f8cSRoland Dreier 
1593d155f8cSRoland Dreier 	dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4);
1603d155f8cSRoland Dreier 	if (!dev->catas_err.map) {
1613d155f8cSRoland Dreier 		mthca_warn(dev, "couldn't map catastrophic error region "
162eb4a7cbfSJohn L. Burr 			   "at 0x%llx/0x%x\n", (unsigned long long) addr,
163eb4a7cbfSJohn L. Burr 			   dev->catas_err.size * 4);
1643d155f8cSRoland Dreier 		return;
1653d155f8cSRoland Dreier 	}
1663d155f8cSRoland Dreier 
1673d155f8cSRoland Dreier 	dev->catas_err.timer.expires  = jiffies + MTHCA_CATAS_POLL_INTERVAL;
168b3b30f5eSJack Morgenstein 	INIT_LIST_HEAD(&dev->catas_err.list);
1693d155f8cSRoland Dreier 	add_timer(&dev->catas_err.timer);
1703d155f8cSRoland Dreier }
1713d155f8cSRoland Dreier 
mthca_stop_catas_poll(struct mthca_dev * dev)1723d155f8cSRoland Dreier void mthca_stop_catas_poll(struct mthca_dev *dev)
1733d155f8cSRoland Dreier {
1743d155f8cSRoland Dreier 	del_timer_sync(&dev->catas_err.timer);
1753d155f8cSRoland Dreier 
176208dde28SRoland Dreier 	if (dev->catas_err.map)
1773d155f8cSRoland Dreier 		iounmap(dev->catas_err.map);
178b3b30f5eSJack Morgenstein 
179b3b30f5eSJack Morgenstein 	spin_lock_irq(&catas_lock);
180b3b30f5eSJack Morgenstein 	list_del(&dev->catas_err.list);
181b3b30f5eSJack Morgenstein 	spin_unlock_irq(&catas_lock);
182b3b30f5eSJack Morgenstein }
183b3b30f5eSJack Morgenstein 
mthca_catas_init(void)184b3b30f5eSJack Morgenstein int __init mthca_catas_init(void)
185b3b30f5eSJack Morgenstein {
186c4028958SDavid Howells 	INIT_WORK(&catas_work, catas_reset);
187b3b30f5eSJack Morgenstein 
188401f047eSBhaktipriya Shridhar 	catas_wq = alloc_ordered_workqueue("mthca_catas", WQ_MEM_RECLAIM);
189b3b30f5eSJack Morgenstein 	if (!catas_wq)
190b3b30f5eSJack Morgenstein 		return -ENOMEM;
191b3b30f5eSJack Morgenstein 
192b3b30f5eSJack Morgenstein 	return 0;
193b3b30f5eSJack Morgenstein }
194b3b30f5eSJack Morgenstein 
mthca_catas_cleanup(void)195b3b30f5eSJack Morgenstein void mthca_catas_cleanup(void)
196b3b30f5eSJack Morgenstein {
197b3b30f5eSJack Morgenstein 	destroy_workqueue(catas_wq);
1983d155f8cSRoland Dreier }
199