Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. |
Jack Morgenstein | 51a379d | 2008-07-25 10:32:52 -0700 | [diff] [blame] | 3 | * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved. |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 4 | * |
| 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 Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 34 | #include <linux/workqueue.h> |
| 35 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 36 | #include "mlx4.h" |
| 37 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 38 | enum { |
| 39 | MLX4_CATAS_POLL_INTERVAL = 5 * HZ, |
| 40 | }; |
| 41 | |
| 42 | static DEFINE_SPINLOCK(catas_lock); |
| 43 | |
| 44 | static LIST_HEAD(catas_list); |
| 45 | static struct workqueue_struct *catas_wq; |
| 46 | static struct work_struct catas_work; |
| 47 | |
| 48 | static int internal_err_reset = 1; |
| 49 | module_param(internal_err_reset, int, 0644); |
| 50 | MODULE_PARM_DESC(internal_err_reset, |
| 51 | "Reset device on internal errors if non-zero (default 1)"); |
| 52 | |
| 53 | static void dump_err_buf(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 54 | { |
| 55 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 56 | |
| 57 | int i; |
| 58 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 59 | mlx4_err(dev, "Internal error detected:\n"); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 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))); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 65 | static void poll_catas(unsigned long dev_ptr) |
| 66 | { |
| 67 | struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr; |
| 68 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 69 | |
| 70 | if (readl(priv->catas_err.map)) { |
| 71 | dump_err_buf(dev); |
| 72 | |
Roland Dreier | 37608ee | 2008-04-16 21:01:08 -0700 | [diff] [blame] | 73 | mlx4_dispatch_event(dev, MLX4_DEV_EVENT_CATASTROPHIC_ERROR, 0); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 74 | |
| 75 | if (internal_err_reset) { |
| 76 | spin_lock(&catas_lock); |
| 77 | list_add(&priv->catas_err.list, &catas_list); |
| 78 | spin_unlock(&catas_lock); |
| 79 | |
| 80 | queue_work(catas_wq, &catas_work); |
| 81 | } |
| 82 | } else |
| 83 | mod_timer(&priv->catas_err.timer, |
| 84 | round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL)); |
| 85 | } |
| 86 | |
| 87 | static void catas_reset(struct work_struct *work) |
| 88 | { |
| 89 | struct mlx4_priv *priv, *tmppriv; |
| 90 | struct mlx4_dev *dev; |
| 91 | |
| 92 | LIST_HEAD(tlist); |
| 93 | int ret; |
| 94 | |
| 95 | spin_lock_irq(&catas_lock); |
| 96 | list_splice_init(&catas_list, &tlist); |
| 97 | spin_unlock_irq(&catas_lock); |
| 98 | |
| 99 | list_for_each_entry_safe(priv, tmppriv, &tlist, catas_err.list) { |
| 100 | ret = mlx4_restart_one(priv->dev.pdev); |
| 101 | dev = &priv->dev; |
| 102 | if (ret) |
| 103 | mlx4_err(dev, "Reset failed (%d)\n", ret); |
| 104 | else |
| 105 | mlx4_dbg(dev, "Reset succeeded\n"); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void mlx4_start_catas_poll(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 110 | { |
| 111 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 112 | unsigned long addr; |
| 113 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 114 | INIT_LIST_HEAD(&priv->catas_err.list); |
| 115 | init_timer(&priv->catas_err.timer); |
| 116 | priv->catas_err.map = NULL; |
| 117 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 118 | addr = pci_resource_start(dev->pdev, priv->fw.catas_bar) + |
| 119 | priv->fw.catas_offset; |
| 120 | |
| 121 | priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 122 | if (!priv->catas_err.map) { |
| 123 | mlx4_warn(dev, "Failed to map internal error buffer at 0x%lx\n", |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 124 | addr); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 125 | return; |
| 126 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 127 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 128 | priv->catas_err.timer.data = (unsigned long) dev; |
| 129 | priv->catas_err.timer.function = poll_catas; |
| 130 | priv->catas_err.timer.expires = |
| 131 | round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL); |
| 132 | add_timer(&priv->catas_err.timer); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 135 | void mlx4_stop_catas_poll(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 136 | { |
| 137 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 138 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 139 | del_timer_sync(&priv->catas_err.timer); |
| 140 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 141 | if (priv->catas_err.map) |
| 142 | iounmap(priv->catas_err.map); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 143 | |
| 144 | spin_lock_irq(&catas_lock); |
| 145 | list_del(&priv->catas_err.list); |
| 146 | spin_unlock_irq(&catas_lock); |
| 147 | } |
| 148 | |
| 149 | int __init mlx4_catas_init(void) |
| 150 | { |
| 151 | INIT_WORK(&catas_work, catas_reset); |
| 152 | |
| 153 | catas_wq = create_singlethread_workqueue("mlx4_err"); |
| 154 | if (!catas_wq) |
| 155 | return -ENOMEM; |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | void mlx4_catas_cleanup(void) |
| 161 | { |
| 162 | destroy_workqueue(catas_wq); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 163 | } |