catas.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
  3. * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
  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. #include <linux/workqueue.h>
  34. #include "mlx4.h"
  35. enum {
  36. MLX4_CATAS_POLL_INTERVAL = 5 * HZ,
  37. };
  38. static DEFINE_SPINLOCK(catas_lock);
  39. static LIST_HEAD(catas_list);
  40. static struct workqueue_struct *catas_wq;
  41. static struct work_struct catas_work;
  42. static int internal_err_reset = 1;
  43. module_param(internal_err_reset, int, 0644);
  44. MODULE_PARM_DESC(internal_err_reset,
  45. "Reset device on internal errors if non-zero (default 1)");
  46. static void dump_err_buf(struct mlx4_dev *dev)
  47. {
  48. struct mlx4_priv *priv = mlx4_priv(dev);
  49. int i;
  50. mlx4_err(dev, "Internal error detected:\n");
  51. for (i = 0; i < priv->fw.catas_size; ++i)
  52. mlx4_err(dev, " buf[%02x]: %08x\n",
  53. i, swab32(readl(priv->catas_err.map + i)));
  54. }
  55. static void poll_catas(unsigned long dev_ptr)
  56. {
  57. struct mlx4_dev *dev = (struct mlx4_dev *) dev_ptr;
  58. struct mlx4_priv *priv = mlx4_priv(dev);
  59. if (readl(priv->catas_err.map)) {
  60. dump_err_buf(dev);
  61. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_CATASTROPHIC_ERROR, 0);
  62. if (internal_err_reset) {
  63. spin_lock(&catas_lock);
  64. list_add(&priv->catas_err.list, &catas_list);
  65. spin_unlock(&catas_lock);
  66. queue_work(catas_wq, &catas_work);
  67. }
  68. } else
  69. mod_timer(&priv->catas_err.timer,
  70. round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL));
  71. }
  72. static void catas_reset(struct work_struct *work)
  73. {
  74. struct mlx4_priv *priv, *tmppriv;
  75. struct mlx4_dev *dev;
  76. LIST_HEAD(tlist);
  77. int ret;
  78. spin_lock_irq(&catas_lock);
  79. list_splice_init(&catas_list, &tlist);
  80. spin_unlock_irq(&catas_lock);
  81. list_for_each_entry_safe(priv, tmppriv, &tlist, catas_err.list) {
  82. ret = mlx4_restart_one(priv->dev.pdev);
  83. dev = &priv->dev;
  84. if (ret)
  85. mlx4_err(dev, "Reset failed (%d)\n", ret);
  86. else
  87. mlx4_dbg(dev, "Reset succeeded\n");
  88. }
  89. }
  90. void mlx4_start_catas_poll(struct mlx4_dev *dev)
  91. {
  92. struct mlx4_priv *priv = mlx4_priv(dev);
  93. unsigned long addr;
  94. INIT_LIST_HEAD(&priv->catas_err.list);
  95. init_timer(&priv->catas_err.timer);
  96. priv->catas_err.map = NULL;
  97. addr = pci_resource_start(dev->pdev, priv->fw.catas_bar) +
  98. priv->fw.catas_offset;
  99. priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4);
  100. if (!priv->catas_err.map) {
  101. mlx4_warn(dev, "Failed to map internal error buffer at 0x%lx\n",
  102. addr);
  103. return;
  104. }
  105. priv->catas_err.timer.data = (unsigned long) dev;
  106. priv->catas_err.timer.function = poll_catas;
  107. priv->catas_err.timer.expires =
  108. round_jiffies(jiffies + MLX4_CATAS_POLL_INTERVAL);
  109. add_timer(&priv->catas_err.timer);
  110. }
  111. void mlx4_stop_catas_poll(struct mlx4_dev *dev)
  112. {
  113. struct mlx4_priv *priv = mlx4_priv(dev);
  114. del_timer_sync(&priv->catas_err.timer);
  115. if (priv->catas_err.map)
  116. iounmap(priv->catas_err.map);
  117. spin_lock_irq(&catas_lock);
  118. list_del(&priv->catas_err.list);
  119. spin_unlock_irq(&catas_lock);
  120. }
  121. int __init mlx4_catas_init(void)
  122. {
  123. INIT_WORK(&catas_work, catas_reset);
  124. catas_wq = create_singlethread_workqueue("mlx4_err");
  125. if (!catas_wq)
  126. return -ENOMEM;
  127. return 0;
  128. }
  129. void mlx4_catas_cleanup(void)
  130. {
  131. destroy_workqueue(catas_wq);
  132. }