Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 302bdf6 | 2015-04-02 17:07:29 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 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 | |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/random.h> |
| 36 | #include <linux/vmalloc.h> |
| 37 | #include <linux/mlx5/driver.h> |
| 38 | #include <linux/mlx5/cmd.h> |
| 39 | #include "mlx5_core.h" |
| 40 | |
| 41 | enum { |
| 42 | MLX5_HEALTH_POLL_INTERVAL = 2 * HZ, |
| 43 | MAX_MISSES = 3, |
| 44 | }; |
| 45 | |
| 46 | enum { |
| 47 | MLX5_HEALTH_SYNDR_FW_ERR = 0x1, |
| 48 | MLX5_HEALTH_SYNDR_IRISC_ERR = 0x7, |
Eli Cohen | 171bb2c | 2015-09-25 10:49:16 +0300 | [diff] [blame] | 49 | MLX5_HEALTH_SYNDR_HW_UNRECOVERABLE_ERR = 0x8, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 50 | MLX5_HEALTH_SYNDR_CRC_ERR = 0x9, |
| 51 | MLX5_HEALTH_SYNDR_FETCH_PCI_ERR = 0xa, |
| 52 | MLX5_HEALTH_SYNDR_HW_FTL_ERR = 0xb, |
| 53 | MLX5_HEALTH_SYNDR_ASYNC_EQ_OVERRUN_ERR = 0xc, |
| 54 | MLX5_HEALTH_SYNDR_EQ_ERR = 0xd, |
Eli Cohen | 171bb2c | 2015-09-25 10:49:16 +0300 | [diff] [blame] | 55 | MLX5_HEALTH_SYNDR_EQ_INV = 0xe, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 56 | MLX5_HEALTH_SYNDR_FFSER_ERR = 0xf, |
Eli Cohen | 171bb2c | 2015-09-25 10:49:16 +0300 | [diff] [blame] | 57 | MLX5_HEALTH_SYNDR_HIGH_TEMP = 0x10 |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 58 | }; |
| 59 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 60 | static void health_care(struct work_struct *work) |
| 61 | { |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 62 | struct mlx5_core_health *health; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 63 | struct mlx5_core_dev *dev; |
| 64 | struct mlx5_priv *priv; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 65 | |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 66 | health = container_of(work, struct mlx5_core_health, work); |
| 67 | priv = container_of(health, struct mlx5_priv, health); |
| 68 | dev = container_of(priv, struct mlx5_core_dev, priv); |
| 69 | mlx5_core_warn(dev, "handling bad device here\n"); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static const char *hsynd_str(u8 synd) |
| 73 | { |
| 74 | switch (synd) { |
| 75 | case MLX5_HEALTH_SYNDR_FW_ERR: |
| 76 | return "firmware internal error"; |
| 77 | case MLX5_HEALTH_SYNDR_IRISC_ERR: |
| 78 | return "irisc not responding"; |
Eli Cohen | 171bb2c | 2015-09-25 10:49:16 +0300 | [diff] [blame] | 79 | case MLX5_HEALTH_SYNDR_HW_UNRECOVERABLE_ERR: |
| 80 | return "unrecoverable hardware error"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 81 | case MLX5_HEALTH_SYNDR_CRC_ERR: |
| 82 | return "firmware CRC error"; |
| 83 | case MLX5_HEALTH_SYNDR_FETCH_PCI_ERR: |
| 84 | return "ICM fetch PCI error"; |
| 85 | case MLX5_HEALTH_SYNDR_HW_FTL_ERR: |
| 86 | return "HW fatal error\n"; |
| 87 | case MLX5_HEALTH_SYNDR_ASYNC_EQ_OVERRUN_ERR: |
| 88 | return "async EQ buffer overrun"; |
| 89 | case MLX5_HEALTH_SYNDR_EQ_ERR: |
| 90 | return "EQ error"; |
Eli Cohen | 171bb2c | 2015-09-25 10:49:16 +0300 | [diff] [blame] | 91 | case MLX5_HEALTH_SYNDR_EQ_INV: |
| 92 | return "Invalid EQ refrenced"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 93 | case MLX5_HEALTH_SYNDR_FFSER_ERR: |
| 94 | return "FFSER error"; |
Eli Cohen | 171bb2c | 2015-09-25 10:49:16 +0300 | [diff] [blame] | 95 | case MLX5_HEALTH_SYNDR_HIGH_TEMP: |
| 96 | return "High temprature"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 97 | default: |
| 98 | return "unrecognized error"; |
| 99 | } |
| 100 | } |
| 101 | |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 102 | static u16 get_maj(u32 fw) |
Roland Dreier | 582c016 | 2013-07-08 10:52:28 -0700 | [diff] [blame] | 103 | { |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 104 | return fw >> 28; |
Roland Dreier | 582c016 | 2013-07-08 10:52:28 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 107 | static u16 get_min(u32 fw) |
Roland Dreier | 582c016 | 2013-07-08 10:52:28 -0700 | [diff] [blame] | 108 | { |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 109 | return fw >> 16 & 0xfff; |
| 110 | } |
| 111 | |
| 112 | static u16 get_sub(u32 fw) |
| 113 | { |
| 114 | return fw & 0xffff; |
Roland Dreier | 582c016 | 2013-07-08 10:52:28 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 117 | static void print_health_info(struct mlx5_core_dev *dev) |
| 118 | { |
| 119 | struct mlx5_core_health *health = &dev->priv.health; |
| 120 | struct health_buffer __iomem *h = health->health; |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 121 | char fw_str[18]; |
| 122 | u32 fw; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 123 | int i; |
| 124 | |
| 125 | for (i = 0; i < ARRAY_SIZE(h->assert_var); i++) |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 126 | dev_err(&dev->pdev->dev, "assert_var[%d] 0x%08x\n", i, ioread32be(h->assert_var + i)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 127 | |
Eli Cohen | 0144a95 | 2015-10-08 17:13:59 +0300 | [diff] [blame] | 128 | dev_err(&dev->pdev->dev, "assert_exit_ptr 0x%08x\n", ioread32be(&h->assert_exit_ptr)); |
| 129 | dev_err(&dev->pdev->dev, "assert_callra 0x%08x\n", ioread32be(&h->assert_callra)); |
| 130 | fw = ioread32be(&h->fw_ver); |
| 131 | sprintf(fw_str, "%d.%d.%d", get_maj(fw), get_min(fw), get_sub(fw)); |
| 132 | dev_err(&dev->pdev->dev, "fw_ver %s\n", fw_str); |
| 133 | dev_err(&dev->pdev->dev, "hw_id 0x%08x\n", ioread32be(&h->hw_id)); |
| 134 | dev_err(&dev->pdev->dev, "irisc_index %d\n", ioread8(&h->irisc_index)); |
| 135 | dev_err(&dev->pdev->dev, "synd 0x%x: %s\n", ioread8(&h->synd), hsynd_str(ioread8(&h->synd))); |
| 136 | dev_err(&dev->pdev->dev, "ext_synd 0x%04x\n", ioread16be(&h->ext_synd)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static void poll_health(unsigned long data) |
| 140 | { |
| 141 | struct mlx5_core_dev *dev = (struct mlx5_core_dev *)data; |
| 142 | struct mlx5_core_health *health = &dev->priv.health; |
| 143 | unsigned long next; |
| 144 | u32 count; |
| 145 | |
| 146 | count = ioread32be(health->health_counter); |
| 147 | if (count == health->prev) |
| 148 | ++health->miss_counter; |
| 149 | else |
| 150 | health->miss_counter = 0; |
| 151 | |
| 152 | health->prev = count; |
| 153 | if (health->miss_counter == MAX_MISSES) { |
| 154 | mlx5_core_err(dev, "device's health compromised\n"); |
| 155 | print_health_info(dev); |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 156 | queue_work(health->wq, &health->work); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 157 | } else { |
| 158 | get_random_bytes(&next, sizeof(next)); |
| 159 | next %= HZ; |
| 160 | next += jiffies + MLX5_HEALTH_POLL_INTERVAL; |
| 161 | mod_timer(&health->timer, next); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void mlx5_start_health_poll(struct mlx5_core_dev *dev) |
| 166 | { |
| 167 | struct mlx5_core_health *health = &dev->priv.health; |
| 168 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 169 | init_timer(&health->timer); |
| 170 | health->health = &dev->iseg->health; |
| 171 | health->health_counter = &dev->iseg->health_counter; |
| 172 | |
| 173 | health->timer.data = (unsigned long)dev; |
| 174 | health->timer.function = poll_health; |
| 175 | health->timer.expires = round_jiffies(jiffies + MLX5_HEALTH_POLL_INTERVAL); |
| 176 | add_timer(&health->timer); |
| 177 | } |
| 178 | |
| 179 | void mlx5_stop_health_poll(struct mlx5_core_dev *dev) |
| 180 | { |
| 181 | struct mlx5_core_health *health = &dev->priv.health; |
| 182 | |
| 183 | del_timer_sync(&health->timer); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 184 | } |
| 185 | |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 186 | void mlx5_health_cleanup(struct mlx5_core_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 187 | { |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 188 | struct mlx5_core_health *health = &dev->priv.health; |
| 189 | |
| 190 | destroy_workqueue(health->wq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 191 | } |
| 192 | |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 193 | int mlx5_health_init(struct mlx5_core_dev *dev) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 194 | { |
Eli Cohen | ac6ea6e | 2015-10-08 17:14:00 +0300 | [diff] [blame^] | 195 | struct mlx5_core_health *health; |
| 196 | char *name; |
| 197 | |
| 198 | health = &dev->priv.health; |
| 199 | name = kmalloc(64, GFP_KERNEL); |
| 200 | if (!name) |
| 201 | return -ENOMEM; |
| 202 | |
| 203 | strcpy(name, "mlx5_health"); |
| 204 | strcat(name, dev_name(&dev->pdev->dev)); |
| 205 | health->wq = create_singlethread_workqueue(name); |
| 206 | kfree(name); |
| 207 | if (!health->wq) |
| 208 | return -ENOMEM; |
| 209 | |
| 210 | INIT_WORK(&health->work, health_care); |
| 211 | |
| 212 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 213 | } |