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); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 45 | static struct work_struct catas_work; |
| 46 | |
| 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 (default 1)"); |
| 51 | |
| 52 | static void dump_err_buf(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 53 | { |
| 54 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 55 | |
| 56 | int i; |
| 57 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 58 | mlx4_err(dev, "Internal error detected:\n"); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 59 | for (i = 0; i < priv->fw.catas_size; ++i) |
| 60 | mlx4_err(dev, " buf[%02x]: %08x\n", |
| 61 | i, swab32(readl(priv->catas_err.map + i))); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 64 | static void poll_catas(unsigned long dev_ptr) |
| 65 | { |
| 66 | struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr; |
| 67 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 68 | |
| 69 | if (readl(priv->catas_err.map)) { |
| 70 | dump_err_buf(dev); |
| 71 | |
Roland Dreier | 37608ee | 2008-04-16 21:01:08 -0700 | [diff] [blame] | 72 | mlx4_dispatch_event(dev, MLX4_DEV_EVENT_CATASTROPHIC_ERROR, 0); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 73 | |
| 74 | if (internal_err_reset) { |
| 75 | spin_lock(&catas_lock); |
| 76 | list_add(&priv->catas_err.list, &catas_list); |
| 77 | spin_unlock(&catas_lock); |
| 78 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 79 | queue_work(mlx4_wq, &catas_work); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 80 | } |
| 81 | } else |
| 82 | mod_timer(&priv->catas_err.timer, |
| 83 | round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL)); |
| 84 | } |
| 85 | |
| 86 | static void catas_reset(struct work_struct *work) |
| 87 | { |
| 88 | struct mlx4_priv *priv, *tmppriv; |
| 89 | struct mlx4_dev *dev; |
| 90 | |
| 91 | LIST_HEAD(tlist); |
| 92 | int ret; |
| 93 | |
| 94 | spin_lock_irq(&catas_lock); |
| 95 | list_splice_init(&catas_list, &tlist); |
| 96 | spin_unlock_irq(&catas_lock); |
| 97 | |
| 98 | list_for_each_entry_safe(priv, tmppriv, &tlist, catas_err.list) { |
Vitaliy Gusev | 634354d | 2009-09-16 00:00:21 -0700 | [diff] [blame] | 99 | struct pci_dev *pdev = priv->dev.pdev; |
| 100 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 101 | ret = mlx4_restart_one(priv->dev.pdev); |
Vitaliy Gusev | 634354d | 2009-09-16 00:00:21 -0700 | [diff] [blame] | 102 | /* 'priv' now is not valid */ |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 103 | if (ret) |
Joe Perches | 0a645e8 | 2010-07-10 07:22:46 +0000 | [diff] [blame] | 104 | pr_err("mlx4 %s: Reset failed (%d)\n", |
| 105 | pci_name(pdev), ret); |
Vitaliy Gusev | 634354d | 2009-09-16 00:00:21 -0700 | [diff] [blame] | 106 | else { |
| 107 | dev = pci_get_drvdata(pdev); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 108 | mlx4_dbg(dev, "Reset succeeded\n"); |
Vitaliy Gusev | 634354d | 2009-09-16 00:00:21 -0700 | [diff] [blame] | 109 | } |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
| 113 | void mlx4_start_catas_poll(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 114 | { |
| 115 | struct mlx4_priv *priv = mlx4_priv(dev); |
Roland Dreier | 4979d18 | 2011-01-12 09:50:36 -0800 | [diff] [blame] | 116 | phys_addr_t addr; |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 117 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 118 | INIT_LIST_HEAD(&priv->catas_err.list); |
| 119 | init_timer(&priv->catas_err.timer); |
| 120 | priv->catas_err.map = NULL; |
| 121 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 122 | addr = pci_resource_start(dev->pdev, priv->fw.catas_bar) + |
| 123 | priv->fw.catas_offset; |
| 124 | |
| 125 | priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 126 | if (!priv->catas_err.map) { |
Roland Dreier | 4979d18 | 2011-01-12 09:50:36 -0800 | [diff] [blame] | 127 | mlx4_warn(dev, "Failed to map internal error buffer at 0x%llx\n", |
| 128 | (unsigned long long) addr); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 129 | return; |
| 130 | } |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 131 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 132 | priv->catas_err.timer.data = (unsigned long) dev; |
| 133 | priv->catas_err.timer.function = poll_catas; |
| 134 | priv->catas_err.timer.expires = |
| 135 | round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL); |
| 136 | add_timer(&priv->catas_err.timer); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 139 | void mlx4_stop_catas_poll(struct mlx4_dev *dev) |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 140 | { |
| 141 | struct mlx4_priv *priv = mlx4_priv(dev); |
| 142 | |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 143 | del_timer_sync(&priv->catas_err.timer); |
| 144 | |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 145 | if (priv->catas_err.map) |
| 146 | iounmap(priv->catas_err.map); |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 147 | |
| 148 | spin_lock_irq(&catas_lock); |
| 149 | list_del(&priv->catas_err.list); |
| 150 | spin_unlock_irq(&catas_lock); |
| 151 | } |
| 152 | |
Yevgeny Petrilin | 27bf91d | 2009-03-18 19:45:11 -0700 | [diff] [blame] | 153 | void __init mlx4_catas_init(void) |
Jack Morgenstein | ee49bd9 | 2007-07-12 17:50:45 +0300 | [diff] [blame] | 154 | { |
| 155 | INIT_WORK(&catas_work, catas_reset); |
Roland Dreier | 225c7b1 | 2007-05-08 18:00:38 -0700 | [diff] [blame] | 156 | } |