2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/workqueue.h>
35 #include <linux/module.h>
39 #define MLX4_CATAS_POLL_INTERVAL (5 * HZ)
42 static DEFINE_SPINLOCK(catas_lock);
44 static LIST_HEAD(catas_list);
45 static struct work_struct catas_work;
47 static int internal_err_reset = 1;
48 module_param(internal_err_reset, int, 0644);
49 MODULE_PARM_DESC(internal_err_reset,
50 "Reset device on internal errors if non-zero"
51 " (default 1, in SRIOV mode default is 0)");
53 static void dump_err_buf(struct mlx4_dev *dev)
55 struct mlx4_priv *priv = mlx4_priv(dev);
59 mlx4_err(dev, "Internal error detected:\n");
60 for (i = 0; i < priv->fw.catas_size; ++i)
61 mlx4_err(dev, " buf[%02x]: %08x\n",
62 i, swab32(readl(priv->catas_err.map + i)));
65 static void poll_catas(unsigned long dev_ptr)
67 struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr;
68 struct mlx4_priv *priv = mlx4_priv(dev);
70 if (readl(priv->catas_err.map)) {
71 /* If the device is off-line, we cannot try to recover it */
72 if (pci_channel_offline(dev->pdev))
73 mod_timer(&priv->catas_err.timer,
74 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL));
77 mlx4_dispatch_event(dev, MLX4_DEV_EVENT_CATASTROPHIC_ERROR, 0);
79 if (internal_err_reset) {
80 spin_lock(&catas_lock);
81 list_add(&priv->catas_err.list, &catas_list);
82 spin_unlock(&catas_lock);
84 queue_work(mlx4_wq, &catas_work);
88 mod_timer(&priv->catas_err.timer,
89 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL));
92 static void catas_reset(struct work_struct *work)
94 struct mlx4_priv *priv, *tmppriv;
100 spin_lock_irq(&catas_lock);
101 list_splice_init(&catas_list, &tlist);
102 spin_unlock_irq(&catas_lock);
104 list_for_each_entry_safe(priv, tmppriv, &tlist, catas_err.list) {
105 struct pci_dev *pdev = priv->dev.pdev;
107 /* If the device is off-line, we cannot reset it */
108 if (pci_channel_offline(pdev))
111 ret = mlx4_restart_one(priv->dev.pdev);
112 /* 'priv' now is not valid */
114 pr_err("mlx4 %s: Reset failed (%d)\n",
115 pci_name(pdev), ret);
117 dev = pci_get_drvdata(pdev);
118 mlx4_dbg(dev, "Reset succeeded\n");
123 void mlx4_start_catas_poll(struct mlx4_dev *dev)
125 struct mlx4_priv *priv = mlx4_priv(dev);
128 /*If we are in SRIOV the default of the module param must be 0*/
129 if (mlx4_is_mfunc(dev))
130 internal_err_reset = 0;
132 INIT_LIST_HEAD(&priv->catas_err.list);
133 init_timer(&priv->catas_err.timer);
134 priv->catas_err.map = NULL;
136 addr = pci_resource_start(dev->pdev, priv->fw.catas_bar) +
137 priv->fw.catas_offset;
139 priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4);
140 if (!priv->catas_err.map) {
141 mlx4_warn(dev, "Failed to map internal error buffer at 0x%llx\n",
142 (unsigned long long) addr);
146 priv->catas_err.timer.data = (unsigned long) dev;
147 priv->catas_err.timer.function = poll_catas;
148 priv->catas_err.timer.expires =
149 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL);
150 add_timer(&priv->catas_err.timer);
153 void mlx4_stop_catas_poll(struct mlx4_dev *dev)
155 struct mlx4_priv *priv = mlx4_priv(dev);
157 del_timer_sync(&priv->catas_err.timer);
159 if (priv->catas_err.map)
160 iounmap(priv->catas_err.map);
162 spin_lock_irq(&catas_lock);
163 list_del(&priv->catas_err.list);
164 spin_unlock_irq(&catas_lock);
167 void __init mlx4_catas_init(void)
169 INIT_WORK(&catas_work, catas_reset);