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>
40 MLX4_CATAS_POLL_INTERVAL = 5 * HZ,
45 static int internal_err_reset = 1;
46 module_param(internal_err_reset, int, 0644);
47 MODULE_PARM_DESC(internal_err_reset,
48 "Reset device on internal errors if non-zero"
49 " (default 1, in SRIOV mode default is 0)");
51 static int read_vendor_id(struct mlx4_dev *dev)
56 ret = pci_read_config_word(dev->persist->pdev, 0, &vendor_id);
58 mlx4_err(dev, "Failed to read vendor ID, ret=%d\n", ret);
62 if (vendor_id == 0xffff) {
63 mlx4_err(dev, "PCI can't be accessed to read vendor id\n");
70 static int mlx4_reset_master(struct mlx4_dev *dev)
74 if (!pci_channel_offline(dev->persist->pdev)) {
75 err = read_vendor_id(dev);
76 /* If PCI can't be accessed to read vendor ID we assume that its
77 * link was disabled and chip was already reset.
82 err = mlx4_reset(dev);
84 mlx4_err(dev, "Fail to reset HCA\n");
90 void mlx4_enter_error_state(struct mlx4_dev_persistent *persist)
95 if (!internal_err_reset)
98 mutex_lock(&persist->device_state_mutex);
99 if (persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)
103 mlx4_err(dev, "device is going to be reset\n");
104 err = mlx4_reset_master(dev);
107 dev->persist->state |= MLX4_DEVICE_STATE_INTERNAL_ERROR;
108 mlx4_err(dev, "device was reset successfully\n");
109 mutex_unlock(&persist->device_state_mutex);
111 /* At that step HW was already reset, now notify clients */
112 mlx4_dispatch_event(dev, MLX4_DEV_EVENT_CATASTROPHIC_ERROR, 0);
116 mutex_unlock(&persist->device_state_mutex);
119 static void mlx4_handle_error_state(struct mlx4_dev_persistent *persist)
123 mlx4_enter_error_state(persist);
124 err = mlx4_restart_one(persist->pdev);
125 mlx4_info(persist->dev, "mlx4_restart_one was ended, ret=%d\n", err);
128 static void dump_err_buf(struct mlx4_dev *dev)
130 struct mlx4_priv *priv = mlx4_priv(dev);
134 mlx4_err(dev, "Internal error detected:\n");
135 for (i = 0; i < priv->fw.catas_size; ++i)
136 mlx4_err(dev, " buf[%02x]: %08x\n",
137 i, swab32(readl(priv->catas_err.map + i)));
140 static void poll_catas(unsigned long dev_ptr)
142 struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr;
143 struct mlx4_priv *priv = mlx4_priv(dev);
145 if (readl(priv->catas_err.map)) {
150 if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR) {
151 mlx4_warn(dev, "Internal error mark was detected on device\n");
155 mod_timer(&priv->catas_err.timer,
156 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL));
160 if (internal_err_reset)
161 queue_work(dev->persist->catas_wq, &dev->persist->catas_work);
164 static void catas_reset(struct work_struct *work)
166 struct mlx4_dev_persistent *persist =
167 container_of(work, struct mlx4_dev_persistent,
170 mlx4_handle_error_state(persist);
173 void mlx4_start_catas_poll(struct mlx4_dev *dev)
175 struct mlx4_priv *priv = mlx4_priv(dev);
178 /*If we are in SRIOV the default of the module param must be 0*/
179 if (mlx4_is_mfunc(dev))
180 internal_err_reset = 0;
182 INIT_LIST_HEAD(&priv->catas_err.list);
183 init_timer(&priv->catas_err.timer);
184 priv->catas_err.map = NULL;
186 addr = pci_resource_start(dev->persist->pdev, priv->fw.catas_bar) +
187 priv->fw.catas_offset;
189 priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4);
190 if (!priv->catas_err.map) {
191 mlx4_warn(dev, "Failed to map internal error buffer at 0x%llx\n",
192 (unsigned long long) addr);
196 priv->catas_err.timer.data = (unsigned long) dev;
197 priv->catas_err.timer.function = poll_catas;
198 priv->catas_err.timer.expires =
199 round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL);
200 add_timer(&priv->catas_err.timer);
203 void mlx4_stop_catas_poll(struct mlx4_dev *dev)
205 struct mlx4_priv *priv = mlx4_priv(dev);
207 del_timer_sync(&priv->catas_err.timer);
209 if (priv->catas_err.map) {
210 iounmap(priv->catas_err.map);
211 priv->catas_err.map = NULL;
215 int mlx4_catas_init(struct mlx4_dev *dev)
217 INIT_WORK(&dev->persist->catas_work, catas_reset);
218 dev->persist->catas_wq = create_singlethread_workqueue("mlx4_health");
219 if (!dev->persist->catas_wq)
225 void mlx4_catas_end(struct mlx4_dev *dev)
227 if (dev->persist->catas_wq) {
228 destroy_workqueue(dev->persist->catas_wq);
229 dev->persist->catas_wq = NULL;