health.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (c) 2013, Mellanox Technologies inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/random.h>
  35. #include <linux/vmalloc.h>
  36. #include <linux/mlx5/driver.h>
  37. #include <linux/mlx5/cmd.h>
  38. #include "mlx5_core.h"
  39. enum {
  40. MLX5_HEALTH_POLL_INTERVAL = 2 * HZ,
  41. MAX_MISSES = 3,
  42. };
  43. enum {
  44. MLX5_HEALTH_SYNDR_FW_ERR = 0x1,
  45. MLX5_HEALTH_SYNDR_IRISC_ERR = 0x7,
  46. MLX5_HEALTH_SYNDR_CRC_ERR = 0x9,
  47. MLX5_HEALTH_SYNDR_FETCH_PCI_ERR = 0xa,
  48. MLX5_HEALTH_SYNDR_HW_FTL_ERR = 0xb,
  49. MLX5_HEALTH_SYNDR_ASYNC_EQ_OVERRUN_ERR = 0xc,
  50. MLX5_HEALTH_SYNDR_EQ_ERR = 0xd,
  51. MLX5_HEALTH_SYNDR_FFSER_ERR = 0xf,
  52. };
  53. static DEFINE_SPINLOCK(health_lock);
  54. static LIST_HEAD(health_list);
  55. static struct work_struct health_work;
  56. static void health_care(struct work_struct *work)
  57. {
  58. struct mlx5_core_health *health, *n;
  59. struct mlx5_core_dev *dev;
  60. struct mlx5_priv *priv;
  61. LIST_HEAD(tlist);
  62. spin_lock_irq(&health_lock);
  63. list_splice_init(&health_list, &tlist);
  64. spin_unlock_irq(&health_lock);
  65. list_for_each_entry_safe(health, n, &tlist, list) {
  66. priv = container_of(health, struct mlx5_priv, health);
  67. dev = container_of(priv, struct mlx5_core_dev, priv);
  68. mlx5_core_warn(dev, "handling bad device here\n");
  69. /* nothing yet */
  70. spin_lock_irq(&health_lock);
  71. list_del_init(&health->list);
  72. spin_unlock_irq(&health_lock);
  73. }
  74. }
  75. static const char *hsynd_str(u8 synd)
  76. {
  77. switch (synd) {
  78. case MLX5_HEALTH_SYNDR_FW_ERR:
  79. return "firmware internal error";
  80. case MLX5_HEALTH_SYNDR_IRISC_ERR:
  81. return "irisc not responding";
  82. case MLX5_HEALTH_SYNDR_CRC_ERR:
  83. return "firmware CRC error";
  84. case MLX5_HEALTH_SYNDR_FETCH_PCI_ERR:
  85. return "ICM fetch PCI error";
  86. case MLX5_HEALTH_SYNDR_HW_FTL_ERR:
  87. return "HW fatal error\n";
  88. case MLX5_HEALTH_SYNDR_ASYNC_EQ_OVERRUN_ERR:
  89. return "async EQ buffer overrun";
  90. case MLX5_HEALTH_SYNDR_EQ_ERR:
  91. return "EQ error";
  92. case MLX5_HEALTH_SYNDR_FFSER_ERR:
  93. return "FFSER error";
  94. default:
  95. return "unrecognized error";
  96. }
  97. }
  98. static u16 read_be16(__be16 __iomem *p)
  99. {
  100. return swab16(readl((__force u16 __iomem *) p));
  101. }
  102. static u32 read_be32(__be32 __iomem *p)
  103. {
  104. return swab32(readl((__force u32 __iomem *) p));
  105. }
  106. static void print_health_info(struct mlx5_core_dev *dev)
  107. {
  108. struct mlx5_core_health *health = &dev->priv.health;
  109. struct health_buffer __iomem *h = health->health;
  110. int i;
  111. for (i = 0; i < ARRAY_SIZE(h->assert_var); i++)
  112. pr_info("assert_var[%d] 0x%08x\n", i, read_be32(h->assert_var + i));
  113. pr_info("assert_exit_ptr 0x%08x\n", read_be32(&h->assert_exit_ptr));
  114. pr_info("assert_callra 0x%08x\n", read_be32(&h->assert_callra));
  115. pr_info("fw_ver 0x%08x\n", read_be32(&h->fw_ver));
  116. pr_info("hw_id 0x%08x\n", read_be32(&h->hw_id));
  117. pr_info("irisc_index %d\n", readb(&h->irisc_index));
  118. pr_info("synd 0x%x: %s\n", readb(&h->synd), hsynd_str(readb(&h->synd)));
  119. pr_info("ext_sync 0x%04x\n", read_be16(&h->ext_sync));
  120. }
  121. static void poll_health(unsigned long data)
  122. {
  123. struct mlx5_core_dev *dev = (struct mlx5_core_dev *)data;
  124. struct mlx5_core_health *health = &dev->priv.health;
  125. unsigned long next;
  126. u32 count;
  127. count = ioread32be(health->health_counter);
  128. if (count == health->prev)
  129. ++health->miss_counter;
  130. else
  131. health->miss_counter = 0;
  132. health->prev = count;
  133. if (health->miss_counter == MAX_MISSES) {
  134. mlx5_core_err(dev, "device's health compromised\n");
  135. print_health_info(dev);
  136. spin_lock_irq(&health_lock);
  137. list_add_tail(&health->list, &health_list);
  138. spin_unlock_irq(&health_lock);
  139. queue_work(mlx5_core_wq, &health_work);
  140. } else {
  141. get_random_bytes(&next, sizeof(next));
  142. next %= HZ;
  143. next += jiffies + MLX5_HEALTH_POLL_INTERVAL;
  144. mod_timer(&health->timer, next);
  145. }
  146. }
  147. void mlx5_start_health_poll(struct mlx5_core_dev *dev)
  148. {
  149. struct mlx5_core_health *health = &dev->priv.health;
  150. INIT_LIST_HEAD(&health->list);
  151. init_timer(&health->timer);
  152. health->health = &dev->iseg->health;
  153. health->health_counter = &dev->iseg->health_counter;
  154. health->timer.data = (unsigned long)dev;
  155. health->timer.function = poll_health;
  156. health->timer.expires = round_jiffies(jiffies + MLX5_HEALTH_POLL_INTERVAL);
  157. add_timer(&health->timer);
  158. }
  159. void mlx5_stop_health_poll(struct mlx5_core_dev *dev)
  160. {
  161. struct mlx5_core_health *health = &dev->priv.health;
  162. del_timer_sync(&health->timer);
  163. spin_lock_irq(&health_lock);
  164. if (!list_empty(&health->list))
  165. list_del_init(&health->list);
  166. spin_unlock_irq(&health_lock);
  167. }
  168. void mlx5_health_cleanup(void)
  169. {
  170. }
  171. void __init mlx5_health_init(void)
  172. {
  173. INIT_WORK(&health_work, health_care);
  174. }