blob: 9c656fe4983dda7fbb10dd1b195bf12b2808c8e8 [file] [log] [blame]
Roland Dreier225c7b12007-05-08 18:00:38 -07001/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
Jack Morgenstein51a379d2008-07-25 10:32:52 -07003 * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
Roland Dreier225c7b12007-05-08 18:00:38 -07004 *
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:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
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.
23 *
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
31 * SOFTWARE.
32 */
33
Jack Morgensteinee49bd92007-07-12 17:50:45 +030034#include <linux/workqueue.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040035#include <linux/module.h>
Jack Morgensteinee49bd92007-07-12 17:50:45 +030036
Roland Dreier225c7b12007-05-08 18:00:38 -070037#include "mlx4.h"
38
Jack Morgensteinee49bd92007-07-12 17:50:45 +030039enum {
40 MLX4_CATAS_POLL_INTERVAL = 5 * HZ,
41};
42
43static DEFINE_SPINLOCK(catas_lock);
44
45static LIST_HEAD(catas_list);
Jack Morgensteinee49bd92007-07-12 17:50:45 +030046static struct work_struct catas_work;
47
48static int internal_err_reset = 1;
49module_param(internal_err_reset, int, 0644);
50MODULE_PARM_DESC(internal_err_reset,
Jack Morgensteind81c7182011-12-13 04:17:16 +000051 "Reset device on internal errors if non-zero"
52 " (default 1, in SRIOV mode default is 0)");
Jack Morgensteinee49bd92007-07-12 17:50:45 +030053
54static void dump_err_buf(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -070055{
56 struct mlx4_priv *priv = mlx4_priv(dev);
57
58 int i;
59
Jack Morgensteinee49bd92007-07-12 17:50:45 +030060 mlx4_err(dev, "Internal error detected:\n");
Roland Dreier225c7b12007-05-08 18:00:38 -070061 for (i = 0; i < priv->fw.catas_size; ++i)
62 mlx4_err(dev, " buf[%02x]: %08x\n",
63 i, swab32(readl(priv->catas_err.map + i)));
Roland Dreier225c7b12007-05-08 18:00:38 -070064}
65
Jack Morgensteinee49bd92007-07-12 17:50:45 +030066static void poll_catas(unsigned long dev_ptr)
67{
68 struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr;
69 struct mlx4_priv *priv = mlx4_priv(dev);
70
71 if (readl(priv->catas_err.map)) {
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +000072 /* If the device is off-line, we cannot try to recover it */
73 if (pci_channel_offline(dev->pdev))
74 mod_timer(&priv->catas_err.timer,
75 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL));
76 else {
77 dump_err_buf(dev);
78 mlx4_dispatch_event(dev, MLX4_DEV_EVENT_CATASTROPHIC_ERROR, 0);
Jack Morgensteinee49bd92007-07-12 17:50:45 +030079
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +000080 if (internal_err_reset) {
81 spin_lock(&catas_lock);
82 list_add(&priv->catas_err.list, &catas_list);
83 spin_unlock(&catas_lock);
Jack Morgensteinee49bd92007-07-12 17:50:45 +030084
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +000085 queue_work(mlx4_wq, &catas_work);
86 }
Jack Morgensteinee49bd92007-07-12 17:50:45 +030087 }
88 } else
89 mod_timer(&priv->catas_err.timer,
90 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL));
91}
92
93static void catas_reset(struct work_struct *work)
94{
95 struct mlx4_priv *priv, *tmppriv;
96 struct mlx4_dev *dev;
97
98 LIST_HEAD(tlist);
99 int ret;
100
101 spin_lock_irq(&catas_lock);
102 list_splice_init(&catas_list, &tlist);
103 spin_unlock_irq(&catas_lock);
104
105 list_for_each_entry_safe(priv, tmppriv, &tlist, catas_err.list) {
Vitaliy Gusev634354d2009-09-16 00:00:21 -0700106 struct pci_dev *pdev = priv->dev.pdev;
107
Kleber Sacilotto de Souza57dbf292012-07-20 09:55:43 +0000108 /* If the device is off-line, we cannot reset it */
109 if (pci_channel_offline(pdev))
110 continue;
111
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300112 ret = mlx4_restart_one(priv->dev.pdev);
Vitaliy Gusev634354d2009-09-16 00:00:21 -0700113 /* 'priv' now is not valid */
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300114 if (ret)
Joe Perches0a645e82010-07-10 07:22:46 +0000115 pr_err("mlx4 %s: Reset failed (%d)\n",
116 pci_name(pdev), ret);
Vitaliy Gusev634354d2009-09-16 00:00:21 -0700117 else {
118 dev = pci_get_drvdata(pdev);
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300119 mlx4_dbg(dev, "Reset succeeded\n");
Vitaliy Gusev634354d2009-09-16 00:00:21 -0700120 }
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300121 }
122}
123
124void mlx4_start_catas_poll(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -0700125{
126 struct mlx4_priv *priv = mlx4_priv(dev);
Roland Dreier4979d182011-01-12 09:50:36 -0800127 phys_addr_t addr;
Roland Dreier225c7b12007-05-08 18:00:38 -0700128
Jack Morgensteind81c7182011-12-13 04:17:16 +0000129 /*If we are in SRIOV the default of the module param must be 0*/
130 if (mlx4_is_mfunc(dev))
131 internal_err_reset = 0;
132
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300133 INIT_LIST_HEAD(&priv->catas_err.list);
134 init_timer(&priv->catas_err.timer);
135 priv->catas_err.map = NULL;
136
Roland Dreier225c7b12007-05-08 18:00:38 -0700137 addr = pci_resource_start(dev->pdev, priv->fw.catas_bar) +
138 priv->fw.catas_offset;
139
140 priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4);
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300141 if (!priv->catas_err.map) {
Roland Dreier4979d182011-01-12 09:50:36 -0800142 mlx4_warn(dev, "Failed to map internal error buffer at 0x%llx\n",
143 (unsigned long long) addr);
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300144 return;
145 }
Roland Dreier225c7b12007-05-08 18:00:38 -0700146
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300147 priv->catas_err.timer.data = (unsigned long) dev;
148 priv->catas_err.timer.function = poll_catas;
149 priv->catas_err.timer.expires =
150 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL);
151 add_timer(&priv->catas_err.timer);
Roland Dreier225c7b12007-05-08 18:00:38 -0700152}
153
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300154void mlx4_stop_catas_poll(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -0700155{
156 struct mlx4_priv *priv = mlx4_priv(dev);
157
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300158 del_timer_sync(&priv->catas_err.timer);
159
Roland Dreier225c7b12007-05-08 18:00:38 -0700160 if (priv->catas_err.map)
161 iounmap(priv->catas_err.map);
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300162
163 spin_lock_irq(&catas_lock);
164 list_del(&priv->catas_err.list);
165 spin_unlock_irq(&catas_lock);
166}
167
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700168void __init mlx4_catas_init(void)
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300169{
170 INIT_WORK(&catas_work, catas_reset);
Roland Dreier225c7b12007-05-08 18:00:38 -0700171}