octeon_edac-pc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012 Cavium, Inc.
  7. *
  8. * Copyright (C) 2009 Wind River Systems,
  9. * written by Ralf Baechle <ralf@linux-mips.org>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/slab.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/io.h>
  16. #include <linux/edac.h>
  17. #include "edac_core.h"
  18. #include "edac_module.h"
  19. #include <asm/octeon/cvmx.h>
  20. #include <asm/mipsregs.h>
  21. extern int register_co_cache_error_notifier(struct notifier_block *nb);
  22. extern int unregister_co_cache_error_notifier(struct notifier_block *nb);
  23. extern unsigned long long cache_err_dcache[NR_CPUS];
  24. struct co_cache_error {
  25. struct notifier_block notifier;
  26. struct edac_device_ctl_info *ed;
  27. };
  28. /**
  29. * EDAC CPU cache error callback
  30. *
  31. * @event: non-zero if unrecoverable.
  32. */
  33. static int co_cache_error_event(struct notifier_block *this,
  34. unsigned long event, void *ptr)
  35. {
  36. struct co_cache_error *p = container_of(this, struct co_cache_error,
  37. notifier);
  38. unsigned int core = cvmx_get_core_num();
  39. unsigned int cpu = smp_processor_id();
  40. u64 icache_err = read_octeon_c0_icacheerr();
  41. u64 dcache_err;
  42. if (event) {
  43. dcache_err = cache_err_dcache[core];
  44. cache_err_dcache[core] = 0;
  45. } else {
  46. dcache_err = read_octeon_c0_dcacheerr();
  47. }
  48. if (icache_err & 1) {
  49. edac_device_printk(p->ed, KERN_ERR,
  50. "CacheErr (Icache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
  51. (unsigned long long)icache_err, core, cpu,
  52. read_c0_errorepc());
  53. write_octeon_c0_icacheerr(0);
  54. edac_device_handle_ce(p->ed, cpu, 1, "icache");
  55. }
  56. if (dcache_err & 1) {
  57. edac_device_printk(p->ed, KERN_ERR,
  58. "CacheErr (Dcache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
  59. (unsigned long long)dcache_err, core, cpu,
  60. read_c0_errorepc());
  61. if (event)
  62. edac_device_handle_ue(p->ed, cpu, 0, "dcache");
  63. else
  64. edac_device_handle_ce(p->ed, cpu, 0, "dcache");
  65. /* Clear the error indication */
  66. if (OCTEON_IS_OCTEON2())
  67. write_octeon_c0_dcacheerr(1);
  68. else
  69. write_octeon_c0_dcacheerr(0);
  70. }
  71. return NOTIFY_STOP;
  72. }
  73. static int co_cache_error_probe(struct platform_device *pdev)
  74. {
  75. struct co_cache_error *p = devm_kzalloc(&pdev->dev, sizeof(*p),
  76. GFP_KERNEL);
  77. if (!p)
  78. return -ENOMEM;
  79. p->notifier.notifier_call = co_cache_error_event;
  80. platform_set_drvdata(pdev, p);
  81. p->ed = edac_device_alloc_ctl_info(0, "cpu", num_possible_cpus(),
  82. "cache", 2, 0, NULL, 0,
  83. edac_device_alloc_index());
  84. if (!p->ed)
  85. goto err;
  86. p->ed->dev = &pdev->dev;
  87. p->ed->dev_name = dev_name(&pdev->dev);
  88. p->ed->mod_name = "octeon-cpu";
  89. p->ed->ctl_name = "cache";
  90. if (edac_device_add_device(p->ed)) {
  91. pr_err("%s: edac_device_add_device() failed\n", __func__);
  92. goto err1;
  93. }
  94. register_co_cache_error_notifier(&p->notifier);
  95. return 0;
  96. err1:
  97. edac_device_free_ctl_info(p->ed);
  98. err:
  99. return -ENXIO;
  100. }
  101. static int co_cache_error_remove(struct platform_device *pdev)
  102. {
  103. struct co_cache_error *p = platform_get_drvdata(pdev);
  104. unregister_co_cache_error_notifier(&p->notifier);
  105. edac_device_del_device(&pdev->dev);
  106. edac_device_free_ctl_info(p->ed);
  107. return 0;
  108. }
  109. static struct platform_driver co_cache_error_driver = {
  110. .probe = co_cache_error_probe,
  111. .remove = co_cache_error_remove,
  112. .driver = {
  113. .name = "octeon_pc_edac",
  114. }
  115. };
  116. module_platform_driver(co_cache_error_driver);
  117. MODULE_LICENSE("GPL");
  118. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");