2 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/random.h>
36 #include <linux/vmalloc.h>
37 #include <linux/hardirq.h>
38 #include <linux/mlx5/driver.h>
39 #include <linux/mlx5/cmd.h>
40 #include "mlx5_core.h"
43 #include "lib/pci_vsc.h"
44 #include "diag/fw_tracer.h"
47 MLX5_HEALTH_POLL_INTERVAL = 2 * HZ,
52 MLX5_HEALTH_SYNDR_FW_ERR = 0x1,
53 MLX5_HEALTH_SYNDR_IRISC_ERR = 0x7,
54 MLX5_HEALTH_SYNDR_HW_UNRECOVERABLE_ERR = 0x8,
55 MLX5_HEALTH_SYNDR_CRC_ERR = 0x9,
56 MLX5_HEALTH_SYNDR_FETCH_PCI_ERR = 0xa,
57 MLX5_HEALTH_SYNDR_HW_FTL_ERR = 0xb,
58 MLX5_HEALTH_SYNDR_ASYNC_EQ_OVERRUN_ERR = 0xc,
59 MLX5_HEALTH_SYNDR_EQ_ERR = 0xd,
60 MLX5_HEALTH_SYNDR_EQ_INV = 0xe,
61 MLX5_HEALTH_SYNDR_FFSER_ERR = 0xf,
62 MLX5_HEALTH_SYNDR_HIGH_TEMP = 0x10
66 MLX5_DROP_NEW_HEALTH_WORK,
70 MLX5_SENSOR_NO_ERR = 0,
71 MLX5_SENSOR_PCI_COMM_ERR = 1,
72 MLX5_SENSOR_PCI_ERR = 2,
73 MLX5_SENSOR_NIC_DISABLED = 3,
74 MLX5_SENSOR_NIC_SW_RESET = 4,
75 MLX5_SENSOR_FW_SYND_RFR = 5,
78 u8 mlx5_get_nic_state(struct mlx5_core_dev *dev)
80 return (ioread32be(&dev->iseg->cmdq_addr_l_sz) >> 8) & 7;
83 void mlx5_set_nic_state(struct mlx5_core_dev *dev, u8 state)
85 u32 cur_cmdq_addr_l_sz;
87 cur_cmdq_addr_l_sz = ioread32be(&dev->iseg->cmdq_addr_l_sz);
88 iowrite32be((cur_cmdq_addr_l_sz & 0xFFFFF000) |
89 state << MLX5_NIC_IFC_OFFSET,
90 &dev->iseg->cmdq_addr_l_sz);
93 static bool sensor_pci_not_working(struct mlx5_core_dev *dev)
95 struct mlx5_core_health *health = &dev->priv.health;
96 struct health_buffer __iomem *h = health->health;
98 /* Offline PCI reads return 0xffffffff */
99 return (ioread32be(&h->fw_ver) == 0xffffffff);
102 static bool sensor_fw_synd_rfr(struct mlx5_core_dev *dev)
104 struct mlx5_core_health *health = &dev->priv.health;
105 struct health_buffer __iomem *h = health->health;
106 u32 rfr = ioread32be(&h->rfr) >> MLX5_RFR_OFFSET;
107 u8 synd = ioread8(&h->synd);
110 mlx5_core_dbg(dev, "FW requests reset, synd: %d\n", synd);
114 static u32 check_fatal_sensors(struct mlx5_core_dev *dev)
116 if (sensor_pci_not_working(dev))
117 return MLX5_SENSOR_PCI_COMM_ERR;
118 if (pci_channel_offline(dev->pdev))
119 return MLX5_SENSOR_PCI_ERR;
120 if (mlx5_get_nic_state(dev) == MLX5_NIC_IFC_DISABLED)
121 return MLX5_SENSOR_NIC_DISABLED;
122 if (mlx5_get_nic_state(dev) == MLX5_NIC_IFC_SW_RESET)
123 return MLX5_SENSOR_NIC_SW_RESET;
124 if (sensor_fw_synd_rfr(dev))
125 return MLX5_SENSOR_FW_SYND_RFR;
127 return MLX5_SENSOR_NO_ERR;
130 static int lock_sem_sw_reset(struct mlx5_core_dev *dev, bool lock)
132 enum mlx5_vsc_state state;
135 if (!mlx5_core_is_pf(dev))
138 /* Try to lock GW access, this stage doesn't return
139 * EBUSY because locked GW does not mean that other PF
140 * already started the reset.
142 ret = mlx5_vsc_gw_lock(dev);
148 state = lock ? MLX5_VSC_LOCK : MLX5_VSC_UNLOCK;
149 /* At this stage, if the return status == EBUSY, then we know
150 * for sure that another PF started the reset, so don't allow
153 ret = mlx5_vsc_sem_set_space(dev, MLX5_SEMAPHORE_SW_RESET, state);
155 mlx5_core_warn(dev, "Failed to lock SW reset semaphore\n");
157 /* Unlock GW access */
158 mlx5_vsc_gw_unlock(dev);
163 static bool reset_fw_if_needed(struct mlx5_core_dev *dev)
165 bool supported = (ioread32be(&dev->iseg->initializing) >>
166 MLX5_FW_RESET_SUPPORTED_OFFSET) & 1;
172 /* The reset only needs to be issued by one PF. The health buffer is
173 * shared between all functions, and will be cleared during a reset.
174 * Check again to avoid a redundant 2nd reset. If the fatal erros was
175 * PCI related a reset won't help.
177 fatal_error = check_fatal_sensors(dev);
178 if (fatal_error == MLX5_SENSOR_PCI_COMM_ERR ||
179 fatal_error == MLX5_SENSOR_NIC_DISABLED ||
180 fatal_error == MLX5_SENSOR_NIC_SW_RESET) {
181 mlx5_core_warn(dev, "Not issuing FW reset. Either it's already done or won't help.");
185 mlx5_core_warn(dev, "Issuing FW Reset\n");
186 /* Write the NIC interface field to initiate the reset, the command
187 * interface address also resides here, don't overwrite it.
189 mlx5_set_nic_state(dev, MLX5_NIC_IFC_SW_RESET);
194 void mlx5_enter_error_state(struct mlx5_core_dev *dev, bool force)
196 mutex_lock(&dev->intf_state_mutex);
197 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR)
199 if (dev->state == MLX5_DEVICE_STATE_UNINITIALIZED) {
200 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR;
204 if (check_fatal_sensors(dev) || force) {
205 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR;
209 mlx5_notifier_call_chain(dev->priv.events, MLX5_DEV_EVENT_SYS_ERROR, (void *)1);
211 mutex_unlock(&dev->intf_state_mutex);
214 #define MLX5_CRDUMP_WAIT_MS 60000
215 #define MLX5_FW_RESET_WAIT_MS 1000
216 void mlx5_error_sw_reset(struct mlx5_core_dev *dev)
218 unsigned long end, delay_ms = MLX5_FW_RESET_WAIT_MS;
221 mutex_lock(&dev->intf_state_mutex);
222 if (dev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR)
225 mlx5_core_err(dev, "start\n");
227 if (check_fatal_sensors(dev) == MLX5_SENSOR_FW_SYND_RFR) {
228 /* Get cr-dump and reset FW semaphore */
229 lock = lock_sem_sw_reset(dev, true);
231 if (lock == -EBUSY) {
232 delay_ms = MLX5_CRDUMP_WAIT_MS;
233 goto recover_from_sw_reset;
235 /* Execute SW reset */
236 reset_fw_if_needed(dev);
239 recover_from_sw_reset:
240 /* Recover from SW reset */
241 end = jiffies + msecs_to_jiffies(delay_ms);
243 if (mlx5_get_nic_state(dev) == MLX5_NIC_IFC_DISABLED)
247 } while (!time_after(jiffies, end));
249 if (mlx5_get_nic_state(dev) != MLX5_NIC_IFC_DISABLED) {
250 dev_err(&dev->pdev->dev, "NIC IFC still %d after %lums.\n",
251 mlx5_get_nic_state(dev), delay_ms);
254 /* Release FW semaphore if you are the lock owner */
256 lock_sem_sw_reset(dev, false);
258 mlx5_core_err(dev, "end\n");
261 mutex_unlock(&dev->intf_state_mutex);
264 static void mlx5_handle_bad_state(struct mlx5_core_dev *dev)
266 u8 nic_interface = mlx5_get_nic_state(dev);
268 switch (nic_interface) {
269 case MLX5_NIC_IFC_FULL:
270 mlx5_core_warn(dev, "Expected to see disabled NIC but it is full driver\n");
273 case MLX5_NIC_IFC_DISABLED:
274 mlx5_core_warn(dev, "starting teardown\n");
277 case MLX5_NIC_IFC_NO_DRAM_NIC:
278 mlx5_core_warn(dev, "Expected to see disabled NIC but it is no dram nic\n");
281 case MLX5_NIC_IFC_SW_RESET:
282 /* The IFC mode field is 3 bits, so it will read 0x7 in 2 cases:
283 * 1. PCI has been disabled (ie. PCI-AER, PF driver unloaded
284 * and this is a VF), this is not recoverable by SW reset.
285 * Logging of this is handled elsewhere.
286 * 2. FW reset has been issued by another function, driver can
287 * be reloaded to recover after the mode switches to
288 * MLX5_NIC_IFC_DISABLED.
290 if (dev->priv.health.fatal_error != MLX5_SENSOR_PCI_COMM_ERR)
291 mlx5_core_warn(dev, "NIC SW reset in progress\n");
295 mlx5_core_warn(dev, "Expected to see disabled NIC but it is has invalid value %d\n",
299 mlx5_disable_device(dev);
302 /* How much time to wait until health resetting the driver (in msecs) */
303 #define MLX5_RECOVERY_WAIT_MSECS 60000
304 static int mlx5_health_try_recover(struct mlx5_core_dev *dev)
308 mlx5_core_warn(dev, "handling bad device here\n");
309 mlx5_handle_bad_state(dev);
310 end = jiffies + msecs_to_jiffies(MLX5_RECOVERY_WAIT_MSECS);
311 while (sensor_pci_not_working(dev)) {
312 if (time_after(jiffies, end)) {
314 "health recovery flow aborted, PCI reads still not working\n");
320 mlx5_core_err(dev, "starting health recovery flow\n");
321 mlx5_recover_device(dev);
322 if (!test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state) ||
323 check_fatal_sensors(dev)) {
324 mlx5_core_err(dev, "health recovery failed\n");
330 static const char *hsynd_str(u8 synd)
333 case MLX5_HEALTH_SYNDR_FW_ERR:
334 return "firmware internal error";
335 case MLX5_HEALTH_SYNDR_IRISC_ERR:
336 return "irisc not responding";
337 case MLX5_HEALTH_SYNDR_HW_UNRECOVERABLE_ERR:
338 return "unrecoverable hardware error";
339 case MLX5_HEALTH_SYNDR_CRC_ERR:
340 return "firmware CRC error";
341 case MLX5_HEALTH_SYNDR_FETCH_PCI_ERR:
342 return "ICM fetch PCI error";
343 case MLX5_HEALTH_SYNDR_HW_FTL_ERR:
344 return "HW fatal error\n";
345 case MLX5_HEALTH_SYNDR_ASYNC_EQ_OVERRUN_ERR:
346 return "async EQ buffer overrun";
347 case MLX5_HEALTH_SYNDR_EQ_ERR:
349 case MLX5_HEALTH_SYNDR_EQ_INV:
350 return "Invalid EQ referenced";
351 case MLX5_HEALTH_SYNDR_FFSER_ERR:
352 return "FFSER error";
353 case MLX5_HEALTH_SYNDR_HIGH_TEMP:
354 return "High temperature";
356 return "unrecognized error";
360 static void print_health_info(struct mlx5_core_dev *dev)
362 struct mlx5_core_health *health = &dev->priv.health;
363 struct health_buffer __iomem *h = health->health;
368 /* If the syndrome is 0, the device is OK and no need to print buffer */
369 if (!ioread8(&h->synd))
372 for (i = 0; i < ARRAY_SIZE(h->assert_var); i++)
373 mlx5_core_err(dev, "assert_var[%d] 0x%08x\n", i,
374 ioread32be(h->assert_var + i));
376 mlx5_core_err(dev, "assert_exit_ptr 0x%08x\n",
377 ioread32be(&h->assert_exit_ptr));
378 mlx5_core_err(dev, "assert_callra 0x%08x\n",
379 ioread32be(&h->assert_callra));
380 sprintf(fw_str, "%d.%d.%d", fw_rev_maj(dev), fw_rev_min(dev), fw_rev_sub(dev));
381 mlx5_core_err(dev, "fw_ver %s\n", fw_str);
382 mlx5_core_err(dev, "hw_id 0x%08x\n", ioread32be(&h->hw_id));
383 mlx5_core_err(dev, "irisc_index %d\n", ioread8(&h->irisc_index));
384 mlx5_core_err(dev, "synd 0x%x: %s\n", ioread8(&h->synd),
385 hsynd_str(ioread8(&h->synd)));
386 mlx5_core_err(dev, "ext_synd 0x%04x\n", ioread16be(&h->ext_synd));
387 fw = ioread32be(&h->fw_ver);
388 mlx5_core_err(dev, "raw fw_ver 0x%08x\n", fw);
392 mlx5_fw_reporter_diagnose(struct devlink_health_reporter *reporter,
393 struct devlink_fmsg *fmsg)
395 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
396 struct mlx5_core_health *health = &dev->priv.health;
397 struct health_buffer __iomem *h = health->health;
401 synd = ioread8(&h->synd);
402 err = devlink_fmsg_u8_pair_put(fmsg, "Syndrome", synd);
405 return devlink_fmsg_string_pair_put(fmsg, "Description", hsynd_str(synd));
408 struct mlx5_fw_reporter_ctx {
414 mlx5_fw_reporter_ctx_pairs_put(struct devlink_fmsg *fmsg,
415 struct mlx5_fw_reporter_ctx *fw_reporter_ctx)
419 err = devlink_fmsg_u8_pair_put(fmsg, "syndrome",
420 fw_reporter_ctx->err_synd);
423 err = devlink_fmsg_u32_pair_put(fmsg, "fw_miss_counter",
424 fw_reporter_ctx->miss_counter);
431 mlx5_fw_reporter_heath_buffer_data_put(struct mlx5_core_dev *dev,
432 struct devlink_fmsg *fmsg)
434 struct mlx5_core_health *health = &dev->priv.health;
435 struct health_buffer __iomem *h = health->health;
439 if (!ioread8(&h->synd))
442 err = devlink_fmsg_pair_nest_start(fmsg, "health buffer");
445 err = devlink_fmsg_obj_nest_start(fmsg);
448 err = devlink_fmsg_arr_pair_nest_start(fmsg, "assert_var");
452 for (i = 0; i < ARRAY_SIZE(h->assert_var); i++) {
453 err = devlink_fmsg_u32_put(fmsg, ioread32be(h->assert_var + i));
457 err = devlink_fmsg_arr_pair_nest_end(fmsg);
460 err = devlink_fmsg_u32_pair_put(fmsg, "assert_exit_ptr",
461 ioread32be(&h->assert_exit_ptr));
464 err = devlink_fmsg_u32_pair_put(fmsg, "assert_callra",
465 ioread32be(&h->assert_callra));
468 err = devlink_fmsg_u32_pair_put(fmsg, "hw_id", ioread32be(&h->hw_id));
471 err = devlink_fmsg_u8_pair_put(fmsg, "irisc_index",
472 ioread8(&h->irisc_index));
475 err = devlink_fmsg_u8_pair_put(fmsg, "synd", ioread8(&h->synd));
478 err = devlink_fmsg_u32_pair_put(fmsg, "ext_synd",
479 ioread16be(&h->ext_synd));
482 err = devlink_fmsg_u32_pair_put(fmsg, "raw_fw_ver",
483 ioread32be(&h->fw_ver));
486 err = devlink_fmsg_obj_nest_end(fmsg);
489 return devlink_fmsg_pair_nest_end(fmsg);
493 mlx5_fw_reporter_dump(struct devlink_health_reporter *reporter,
494 struct devlink_fmsg *fmsg, void *priv_ctx)
496 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
499 err = mlx5_fw_tracer_trigger_core_dump_general(dev);
504 struct mlx5_fw_reporter_ctx *fw_reporter_ctx = priv_ctx;
506 err = mlx5_fw_reporter_ctx_pairs_put(fmsg, fw_reporter_ctx);
511 err = mlx5_fw_reporter_heath_buffer_data_put(dev, fmsg);
514 return mlx5_fw_tracer_get_saved_traces_objects(dev->tracer, fmsg);
517 static void mlx5_fw_reporter_err_work(struct work_struct *work)
519 struct mlx5_fw_reporter_ctx fw_reporter_ctx;
520 struct mlx5_core_health *health;
522 health = container_of(work, struct mlx5_core_health, report_work);
524 if (IS_ERR_OR_NULL(health->fw_reporter))
527 fw_reporter_ctx.err_synd = health->synd;
528 fw_reporter_ctx.miss_counter = health->miss_counter;
529 if (fw_reporter_ctx.err_synd) {
530 devlink_health_report(health->fw_reporter,
531 "FW syndrom reported", &fw_reporter_ctx);
534 if (fw_reporter_ctx.miss_counter)
535 devlink_health_report(health->fw_reporter,
536 "FW miss counter reported",
540 static const struct devlink_health_reporter_ops mlx5_fw_reporter_ops = {
542 .diagnose = mlx5_fw_reporter_diagnose,
543 .dump = mlx5_fw_reporter_dump,
547 mlx5_fw_fatal_reporter_recover(struct devlink_health_reporter *reporter,
550 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
552 return mlx5_health_try_recover(dev);
555 #define MLX5_CR_DUMP_CHUNK_SIZE 256
557 mlx5_fw_fatal_reporter_dump(struct devlink_health_reporter *reporter,
558 struct devlink_fmsg *fmsg, void *priv_ctx)
560 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
561 u32 crdump_size = dev->priv.health.crdump_size;
567 if (!mlx5_core_is_pf(dev))
570 cr_data = kvmalloc(crdump_size, GFP_KERNEL);
573 err = mlx5_crdump_collect(dev, cr_data);
578 struct mlx5_fw_reporter_ctx *fw_reporter_ctx = priv_ctx;
580 err = mlx5_fw_reporter_ctx_pairs_put(fmsg, fw_reporter_ctx);
585 err = devlink_fmsg_arr_pair_nest_start(fmsg, "crdump_data");
588 for (offset = 0; offset < crdump_size; offset += data_size) {
589 if (crdump_size - offset < MLX5_CR_DUMP_CHUNK_SIZE)
590 data_size = crdump_size - offset;
592 data_size = MLX5_CR_DUMP_CHUNK_SIZE;
593 err = devlink_fmsg_binary_put(fmsg, cr_data, data_size);
597 err = devlink_fmsg_arr_pair_nest_end(fmsg);
604 static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work)
606 struct mlx5_fw_reporter_ctx fw_reporter_ctx;
607 struct mlx5_core_health *health;
608 struct mlx5_core_dev *dev;
609 struct mlx5_priv *priv;
611 health = container_of(work, struct mlx5_core_health, fatal_report_work);
612 priv = container_of(health, struct mlx5_priv, health);
613 dev = container_of(priv, struct mlx5_core_dev, priv);
615 mlx5_enter_error_state(dev, false);
616 if (IS_ERR_OR_NULL(health->fw_fatal_reporter)) {
617 if (mlx5_health_try_recover(dev))
618 mlx5_core_err(dev, "health recovery failed\n");
621 fw_reporter_ctx.err_synd = health->synd;
622 fw_reporter_ctx.miss_counter = health->miss_counter;
623 devlink_health_report(health->fw_fatal_reporter,
624 "FW fatal error reported", &fw_reporter_ctx);
627 static const struct devlink_health_reporter_ops mlx5_fw_fatal_reporter_ops = {
629 .recover = mlx5_fw_fatal_reporter_recover,
630 .dump = mlx5_fw_fatal_reporter_dump,
633 #define MLX5_REPORTER_FW_GRACEFUL_PERIOD 1200000
634 static void mlx5_fw_reporters_create(struct mlx5_core_dev *dev)
636 struct mlx5_core_health *health = &dev->priv.health;
637 struct devlink *devlink = priv_to_devlink(dev);
639 health->fw_reporter =
640 devlink_health_reporter_create(devlink, &mlx5_fw_reporter_ops,
642 if (IS_ERR(health->fw_reporter))
643 mlx5_core_warn(dev, "Failed to create fw reporter, err = %ld\n",
644 PTR_ERR(health->fw_reporter));
646 health->fw_fatal_reporter =
647 devlink_health_reporter_create(devlink,
648 &mlx5_fw_fatal_reporter_ops,
649 MLX5_REPORTER_FW_GRACEFUL_PERIOD,
651 if (IS_ERR(health->fw_fatal_reporter))
652 mlx5_core_warn(dev, "Failed to create fw fatal reporter, err = %ld\n",
653 PTR_ERR(health->fw_fatal_reporter));
656 static void mlx5_fw_reporters_destroy(struct mlx5_core_dev *dev)
658 struct mlx5_core_health *health = &dev->priv.health;
660 if (!IS_ERR_OR_NULL(health->fw_reporter))
661 devlink_health_reporter_destroy(health->fw_reporter);
663 if (!IS_ERR_OR_NULL(health->fw_fatal_reporter))
664 devlink_health_reporter_destroy(health->fw_fatal_reporter);
667 static unsigned long get_next_poll_jiffies(void)
671 get_random_bytes(&next, sizeof(next));
673 next += jiffies + MLX5_HEALTH_POLL_INTERVAL;
678 void mlx5_trigger_health_work(struct mlx5_core_dev *dev)
680 struct mlx5_core_health *health = &dev->priv.health;
683 spin_lock_irqsave(&health->wq_lock, flags);
684 if (!test_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags))
685 queue_work(health->wq, &health->fatal_report_work);
687 mlx5_core_err(dev, "new health works are not permitted at this stage\n");
688 spin_unlock_irqrestore(&health->wq_lock, flags);
691 static void poll_health(struct timer_list *t)
693 struct mlx5_core_dev *dev = from_timer(dev, t, priv.health.timer);
694 struct mlx5_core_health *health = &dev->priv.health;
695 struct health_buffer __iomem *h = health->health;
700 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR)
703 count = ioread32be(health->health_counter);
704 if (count == health->prev)
705 ++health->miss_counter;
707 health->miss_counter = 0;
709 health->prev = count;
710 if (health->miss_counter == MAX_MISSES) {
711 mlx5_core_err(dev, "device's health compromised - reached miss count\n");
712 print_health_info(dev);
713 queue_work(health->wq, &health->report_work);
716 prev_synd = health->synd;
717 health->synd = ioread8(&h->synd);
718 if (health->synd && health->synd != prev_synd)
719 queue_work(health->wq, &health->report_work);
721 fatal_error = check_fatal_sensors(dev);
723 if (fatal_error && !health->fatal_error) {
724 mlx5_core_err(dev, "Fatal error %u detected\n", fatal_error);
725 dev->priv.health.fatal_error = fatal_error;
726 print_health_info(dev);
727 mlx5_trigger_health_work(dev);
731 mod_timer(&health->timer, get_next_poll_jiffies());
734 void mlx5_start_health_poll(struct mlx5_core_dev *dev)
736 struct mlx5_core_health *health = &dev->priv.health;
738 timer_setup(&health->timer, poll_health, 0);
739 health->fatal_error = MLX5_SENSOR_NO_ERR;
740 clear_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
741 health->health = &dev->iseg->health;
742 health->health_counter = &dev->iseg->health_counter;
744 health->timer.expires = round_jiffies(jiffies + MLX5_HEALTH_POLL_INTERVAL);
745 add_timer(&health->timer);
748 void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health)
750 struct mlx5_core_health *health = &dev->priv.health;
753 if (disable_health) {
754 spin_lock_irqsave(&health->wq_lock, flags);
755 set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
756 spin_unlock_irqrestore(&health->wq_lock, flags);
759 del_timer_sync(&health->timer);
762 void mlx5_drain_health_wq(struct mlx5_core_dev *dev)
764 struct mlx5_core_health *health = &dev->priv.health;
767 spin_lock_irqsave(&health->wq_lock, flags);
768 set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
769 spin_unlock_irqrestore(&health->wq_lock, flags);
770 cancel_work_sync(&health->report_work);
771 cancel_work_sync(&health->fatal_report_work);
774 void mlx5_health_flush(struct mlx5_core_dev *dev)
776 struct mlx5_core_health *health = &dev->priv.health;
778 flush_workqueue(health->wq);
781 void mlx5_health_cleanup(struct mlx5_core_dev *dev)
783 struct mlx5_core_health *health = &dev->priv.health;
785 destroy_workqueue(health->wq);
786 mlx5_fw_reporters_destroy(dev);
789 int mlx5_health_init(struct mlx5_core_dev *dev)
791 struct mlx5_core_health *health;
794 mlx5_fw_reporters_create(dev);
796 health = &dev->priv.health;
797 name = kmalloc(64, GFP_KERNEL);
801 strcpy(name, "mlx5_health");
802 strcat(name, dev_name(dev->device));
803 health->wq = create_singlethread_workqueue(name);
807 spin_lock_init(&health->wq_lock);
808 INIT_WORK(&health->fatal_report_work, mlx5_fw_fatal_reporter_err_work);
809 INIT_WORK(&health->report_work, mlx5_fw_reporter_err_work);
814 mlx5_fw_reporters_destroy(dev);