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,
394 struct netlink_ext_ack *extack)
396 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
397 struct mlx5_core_health *health = &dev->priv.health;
398 struct health_buffer __iomem *h = health->health;
402 synd = ioread8(&h->synd);
403 err = devlink_fmsg_u8_pair_put(fmsg, "Syndrome", synd);
406 return devlink_fmsg_string_pair_put(fmsg, "Description", hsynd_str(synd));
409 struct mlx5_fw_reporter_ctx {
415 mlx5_fw_reporter_ctx_pairs_put(struct devlink_fmsg *fmsg,
416 struct mlx5_fw_reporter_ctx *fw_reporter_ctx)
420 err = devlink_fmsg_u8_pair_put(fmsg, "syndrome",
421 fw_reporter_ctx->err_synd);
424 err = devlink_fmsg_u32_pair_put(fmsg, "fw_miss_counter",
425 fw_reporter_ctx->miss_counter);
432 mlx5_fw_reporter_heath_buffer_data_put(struct mlx5_core_dev *dev,
433 struct devlink_fmsg *fmsg)
435 struct mlx5_core_health *health = &dev->priv.health;
436 struct health_buffer __iomem *h = health->health;
440 if (!ioread8(&h->synd))
443 err = devlink_fmsg_pair_nest_start(fmsg, "health buffer");
446 err = devlink_fmsg_obj_nest_start(fmsg);
449 err = devlink_fmsg_arr_pair_nest_start(fmsg, "assert_var");
453 for (i = 0; i < ARRAY_SIZE(h->assert_var); i++) {
454 err = devlink_fmsg_u32_put(fmsg, ioread32be(h->assert_var + i));
458 err = devlink_fmsg_arr_pair_nest_end(fmsg);
461 err = devlink_fmsg_u32_pair_put(fmsg, "assert_exit_ptr",
462 ioread32be(&h->assert_exit_ptr));
465 err = devlink_fmsg_u32_pair_put(fmsg, "assert_callra",
466 ioread32be(&h->assert_callra));
469 err = devlink_fmsg_u32_pair_put(fmsg, "hw_id", ioread32be(&h->hw_id));
472 err = devlink_fmsg_u8_pair_put(fmsg, "irisc_index",
473 ioread8(&h->irisc_index));
476 err = devlink_fmsg_u8_pair_put(fmsg, "synd", ioread8(&h->synd));
479 err = devlink_fmsg_u32_pair_put(fmsg, "ext_synd",
480 ioread16be(&h->ext_synd));
483 err = devlink_fmsg_u32_pair_put(fmsg, "raw_fw_ver",
484 ioread32be(&h->fw_ver));
487 err = devlink_fmsg_obj_nest_end(fmsg);
490 return devlink_fmsg_pair_nest_end(fmsg);
494 mlx5_fw_reporter_dump(struct devlink_health_reporter *reporter,
495 struct devlink_fmsg *fmsg, void *priv_ctx,
496 struct netlink_ext_ack *extack)
498 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
501 err = mlx5_fw_tracer_trigger_core_dump_general(dev);
506 struct mlx5_fw_reporter_ctx *fw_reporter_ctx = priv_ctx;
508 err = mlx5_fw_reporter_ctx_pairs_put(fmsg, fw_reporter_ctx);
513 err = mlx5_fw_reporter_heath_buffer_data_put(dev, fmsg);
516 return mlx5_fw_tracer_get_saved_traces_objects(dev->tracer, fmsg);
519 static void mlx5_fw_reporter_err_work(struct work_struct *work)
521 struct mlx5_fw_reporter_ctx fw_reporter_ctx;
522 struct mlx5_core_health *health;
524 health = container_of(work, struct mlx5_core_health, report_work);
526 if (IS_ERR_OR_NULL(health->fw_reporter))
529 fw_reporter_ctx.err_synd = health->synd;
530 fw_reporter_ctx.miss_counter = health->miss_counter;
531 if (fw_reporter_ctx.err_synd) {
532 devlink_health_report(health->fw_reporter,
533 "FW syndrom reported", &fw_reporter_ctx);
536 if (fw_reporter_ctx.miss_counter)
537 devlink_health_report(health->fw_reporter,
538 "FW miss counter reported",
542 static const struct devlink_health_reporter_ops mlx5_fw_reporter_ops = {
544 .diagnose = mlx5_fw_reporter_diagnose,
545 .dump = mlx5_fw_reporter_dump,
549 mlx5_fw_fatal_reporter_recover(struct devlink_health_reporter *reporter,
551 struct netlink_ext_ack *extack)
553 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
555 return mlx5_health_try_recover(dev);
559 mlx5_fw_fatal_reporter_dump(struct devlink_health_reporter *reporter,
560 struct devlink_fmsg *fmsg, void *priv_ctx,
561 struct netlink_ext_ack *extack)
563 struct mlx5_core_dev *dev = devlink_health_reporter_priv(reporter);
564 u32 crdump_size = dev->priv.health.crdump_size;
568 if (!mlx5_core_is_pf(dev))
571 cr_data = kvmalloc(crdump_size, GFP_KERNEL);
574 err = mlx5_crdump_collect(dev, cr_data);
579 struct mlx5_fw_reporter_ctx *fw_reporter_ctx = priv_ctx;
581 err = mlx5_fw_reporter_ctx_pairs_put(fmsg, fw_reporter_ctx);
586 err = devlink_fmsg_binary_pair_put(fmsg, "crdump_data", cr_data, crdump_size);
593 static void mlx5_fw_fatal_reporter_err_work(struct work_struct *work)
595 struct mlx5_fw_reporter_ctx fw_reporter_ctx;
596 struct mlx5_core_health *health;
597 struct mlx5_core_dev *dev;
598 struct mlx5_priv *priv;
600 health = container_of(work, struct mlx5_core_health, fatal_report_work);
601 priv = container_of(health, struct mlx5_priv, health);
602 dev = container_of(priv, struct mlx5_core_dev, priv);
604 mlx5_enter_error_state(dev, false);
605 if (IS_ERR_OR_NULL(health->fw_fatal_reporter)) {
606 if (mlx5_health_try_recover(dev))
607 mlx5_core_err(dev, "health recovery failed\n");
610 fw_reporter_ctx.err_synd = health->synd;
611 fw_reporter_ctx.miss_counter = health->miss_counter;
612 devlink_health_report(health->fw_fatal_reporter,
613 "FW fatal error reported", &fw_reporter_ctx);
616 static const struct devlink_health_reporter_ops mlx5_fw_fatal_reporter_ops = {
618 .recover = mlx5_fw_fatal_reporter_recover,
619 .dump = mlx5_fw_fatal_reporter_dump,
622 #define MLX5_REPORTER_FW_GRACEFUL_PERIOD 1200000
623 static void mlx5_fw_reporters_create(struct mlx5_core_dev *dev)
625 struct mlx5_core_health *health = &dev->priv.health;
626 struct devlink *devlink = priv_to_devlink(dev);
628 health->fw_reporter =
629 devlink_health_reporter_create(devlink, &mlx5_fw_reporter_ops,
631 if (IS_ERR(health->fw_reporter))
632 mlx5_core_warn(dev, "Failed to create fw reporter, err = %ld\n",
633 PTR_ERR(health->fw_reporter));
635 health->fw_fatal_reporter =
636 devlink_health_reporter_create(devlink,
637 &mlx5_fw_fatal_reporter_ops,
638 MLX5_REPORTER_FW_GRACEFUL_PERIOD,
640 if (IS_ERR(health->fw_fatal_reporter))
641 mlx5_core_warn(dev, "Failed to create fw fatal reporter, err = %ld\n",
642 PTR_ERR(health->fw_fatal_reporter));
645 static void mlx5_fw_reporters_destroy(struct mlx5_core_dev *dev)
647 struct mlx5_core_health *health = &dev->priv.health;
649 if (!IS_ERR_OR_NULL(health->fw_reporter))
650 devlink_health_reporter_destroy(health->fw_reporter);
652 if (!IS_ERR_OR_NULL(health->fw_fatal_reporter))
653 devlink_health_reporter_destroy(health->fw_fatal_reporter);
656 static unsigned long get_next_poll_jiffies(void)
660 get_random_bytes(&next, sizeof(next));
662 next += jiffies + MLX5_HEALTH_POLL_INTERVAL;
667 void mlx5_trigger_health_work(struct mlx5_core_dev *dev)
669 struct mlx5_core_health *health = &dev->priv.health;
672 spin_lock_irqsave(&health->wq_lock, flags);
673 if (!test_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags))
674 queue_work(health->wq, &health->fatal_report_work);
676 mlx5_core_err(dev, "new health works are not permitted at this stage\n");
677 spin_unlock_irqrestore(&health->wq_lock, flags);
680 static void poll_health(struct timer_list *t)
682 struct mlx5_core_dev *dev = from_timer(dev, t, priv.health.timer);
683 struct mlx5_core_health *health = &dev->priv.health;
684 struct health_buffer __iomem *h = health->health;
689 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR)
692 fatal_error = check_fatal_sensors(dev);
694 if (fatal_error && !health->fatal_error) {
695 mlx5_core_err(dev, "Fatal error %u detected\n", fatal_error);
696 dev->priv.health.fatal_error = fatal_error;
697 print_health_info(dev);
698 mlx5_trigger_health_work(dev);
702 count = ioread32be(health->health_counter);
703 if (count == health->prev)
704 ++health->miss_counter;
706 health->miss_counter = 0;
708 health->prev = count;
709 if (health->miss_counter == MAX_MISSES) {
710 mlx5_core_err(dev, "device's health compromised - reached miss count\n");
711 print_health_info(dev);
712 queue_work(health->wq, &health->report_work);
715 prev_synd = health->synd;
716 health->synd = ioread8(&h->synd);
717 if (health->synd && health->synd != prev_synd)
718 queue_work(health->wq, &health->report_work);
721 mod_timer(&health->timer, get_next_poll_jiffies());
724 void mlx5_start_health_poll(struct mlx5_core_dev *dev)
726 struct mlx5_core_health *health = &dev->priv.health;
728 timer_setup(&health->timer, poll_health, 0);
729 health->fatal_error = MLX5_SENSOR_NO_ERR;
730 clear_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
731 health->health = &dev->iseg->health;
732 health->health_counter = &dev->iseg->health_counter;
734 health->timer.expires = round_jiffies(jiffies + MLX5_HEALTH_POLL_INTERVAL);
735 add_timer(&health->timer);
738 void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health)
740 struct mlx5_core_health *health = &dev->priv.health;
743 if (disable_health) {
744 spin_lock_irqsave(&health->wq_lock, flags);
745 set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
746 spin_unlock_irqrestore(&health->wq_lock, flags);
749 del_timer_sync(&health->timer);
752 void mlx5_drain_health_wq(struct mlx5_core_dev *dev)
754 struct mlx5_core_health *health = &dev->priv.health;
757 spin_lock_irqsave(&health->wq_lock, flags);
758 set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
759 spin_unlock_irqrestore(&health->wq_lock, flags);
760 cancel_work_sync(&health->report_work);
761 cancel_work_sync(&health->fatal_report_work);
764 void mlx5_health_flush(struct mlx5_core_dev *dev)
766 struct mlx5_core_health *health = &dev->priv.health;
768 flush_workqueue(health->wq);
771 void mlx5_health_cleanup(struct mlx5_core_dev *dev)
773 struct mlx5_core_health *health = &dev->priv.health;
775 destroy_workqueue(health->wq);
776 mlx5_fw_reporters_destroy(dev);
779 int mlx5_health_init(struct mlx5_core_dev *dev)
781 struct mlx5_core_health *health;
784 mlx5_fw_reporters_create(dev);
786 health = &dev->priv.health;
787 name = kmalloc(64, GFP_KERNEL);
791 strcpy(name, "mlx5_health");
792 strcat(name, dev_name(dev->device));
793 health->wq = create_singlethread_workqueue(name);
797 spin_lock_init(&health->wq_lock);
798 INIT_WORK(&health->fatal_report_work, mlx5_fw_fatal_reporter_err_work);
799 INIT_WORK(&health->report_work, mlx5_fw_reporter_err_work);
804 mlx5_fw_reporters_destroy(dev);