octeon_edac-l2c.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/io.h>
  15. #include <linux/edac.h>
  16. #include <asm/octeon/cvmx.h>
  17. #include "edac_core.h"
  18. #include "edac_module.h"
  19. #define EDAC_MOD_STR "octeon-l2c"
  20. static void octeon_l2c_poll_oct1(struct edac_device_ctl_info *l2c)
  21. {
  22. union cvmx_l2t_err l2t_err, l2t_err_reset;
  23. union cvmx_l2d_err l2d_err, l2d_err_reset;
  24. l2t_err_reset.u64 = 0;
  25. l2t_err.u64 = cvmx_read_csr(CVMX_L2T_ERR);
  26. if (l2t_err.s.sec_err) {
  27. edac_device_handle_ce(l2c, 0, 0,
  28. "Tag Single bit error (corrected)");
  29. l2t_err_reset.s.sec_err = 1;
  30. }
  31. if (l2t_err.s.ded_err) {
  32. edac_device_handle_ue(l2c, 0, 0,
  33. "Tag Double bit error (detected)");
  34. l2t_err_reset.s.ded_err = 1;
  35. }
  36. if (l2t_err_reset.u64)
  37. cvmx_write_csr(CVMX_L2T_ERR, l2t_err_reset.u64);
  38. l2d_err_reset.u64 = 0;
  39. l2d_err.u64 = cvmx_read_csr(CVMX_L2D_ERR);
  40. if (l2d_err.s.sec_err) {
  41. edac_device_handle_ce(l2c, 0, 1,
  42. "Data Single bit error (corrected)");
  43. l2d_err_reset.s.sec_err = 1;
  44. }
  45. if (l2d_err.s.ded_err) {
  46. edac_device_handle_ue(l2c, 0, 1,
  47. "Data Double bit error (detected)");
  48. l2d_err_reset.s.ded_err = 1;
  49. }
  50. if (l2d_err_reset.u64)
  51. cvmx_write_csr(CVMX_L2D_ERR, l2d_err_reset.u64);
  52. }
  53. static void _octeon_l2c_poll_oct2(struct edac_device_ctl_info *l2c, int tad)
  54. {
  55. union cvmx_l2c_err_tdtx err_tdtx, err_tdtx_reset;
  56. union cvmx_l2c_err_ttgx err_ttgx, err_ttgx_reset;
  57. char buf1[64];
  58. char buf2[80];
  59. err_tdtx_reset.u64 = 0;
  60. err_tdtx.u64 = cvmx_read_csr(CVMX_L2C_ERR_TDTX(tad));
  61. if (err_tdtx.s.dbe || err_tdtx.s.sbe ||
  62. err_tdtx.s.vdbe || err_tdtx.s.vsbe)
  63. snprintf(buf1, sizeof(buf1),
  64. "type:%d, syn:0x%x, way:%d",
  65. err_tdtx.s.type, err_tdtx.s.syn, err_tdtx.s.wayidx);
  66. if (err_tdtx.s.dbe) {
  67. snprintf(buf2, sizeof(buf2),
  68. "L2D Double bit error (detected):%s", buf1);
  69. err_tdtx_reset.s.dbe = 1;
  70. edac_device_handle_ue(l2c, tad, 1, buf2);
  71. }
  72. if (err_tdtx.s.sbe) {
  73. snprintf(buf2, sizeof(buf2),
  74. "L2D Single bit error (corrected):%s", buf1);
  75. err_tdtx_reset.s.sbe = 1;
  76. edac_device_handle_ce(l2c, tad, 1, buf2);
  77. }
  78. if (err_tdtx.s.vdbe) {
  79. snprintf(buf2, sizeof(buf2),
  80. "VBF Double bit error (detected):%s", buf1);
  81. err_tdtx_reset.s.vdbe = 1;
  82. edac_device_handle_ue(l2c, tad, 1, buf2);
  83. }
  84. if (err_tdtx.s.vsbe) {
  85. snprintf(buf2, sizeof(buf2),
  86. "VBF Single bit error (corrected):%s", buf1);
  87. err_tdtx_reset.s.vsbe = 1;
  88. edac_device_handle_ce(l2c, tad, 1, buf2);
  89. }
  90. if (err_tdtx_reset.u64)
  91. cvmx_write_csr(CVMX_L2C_ERR_TDTX(tad), err_tdtx_reset.u64);
  92. err_ttgx_reset.u64 = 0;
  93. err_ttgx.u64 = cvmx_read_csr(CVMX_L2C_ERR_TTGX(tad));
  94. if (err_ttgx.s.dbe || err_ttgx.s.sbe)
  95. snprintf(buf1, sizeof(buf1),
  96. "type:%d, syn:0x%x, way:%d",
  97. err_ttgx.s.type, err_ttgx.s.syn, err_ttgx.s.wayidx);
  98. if (err_ttgx.s.dbe) {
  99. snprintf(buf2, sizeof(buf2),
  100. "Tag Double bit error (detected):%s", buf1);
  101. err_ttgx_reset.s.dbe = 1;
  102. edac_device_handle_ue(l2c, tad, 0, buf2);
  103. }
  104. if (err_ttgx.s.sbe) {
  105. snprintf(buf2, sizeof(buf2),
  106. "Tag Single bit error (corrected):%s", buf1);
  107. err_ttgx_reset.s.sbe = 1;
  108. edac_device_handle_ce(l2c, tad, 0, buf2);
  109. }
  110. if (err_ttgx_reset.u64)
  111. cvmx_write_csr(CVMX_L2C_ERR_TTGX(tad), err_ttgx_reset.u64);
  112. }
  113. static void octeon_l2c_poll_oct2(struct edac_device_ctl_info *l2c)
  114. {
  115. int i;
  116. for (i = 0; i < l2c->nr_instances; i++)
  117. _octeon_l2c_poll_oct2(l2c, i);
  118. }
  119. static int octeon_l2c_probe(struct platform_device *pdev)
  120. {
  121. struct edac_device_ctl_info *l2c;
  122. int num_tads = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 : 1;
  123. /* 'Tags' are block 0, 'Data' is block 1*/
  124. l2c = edac_device_alloc_ctl_info(0, "l2c", num_tads, "l2c", 2, 0,
  125. NULL, 0, edac_device_alloc_index());
  126. if (!l2c)
  127. return -ENOMEM;
  128. l2c->dev = &pdev->dev;
  129. platform_set_drvdata(pdev, l2c);
  130. l2c->dev_name = dev_name(&pdev->dev);
  131. l2c->mod_name = "octeon-l2c";
  132. l2c->ctl_name = "octeon_l2c_err";
  133. if (OCTEON_IS_OCTEON1PLUS()) {
  134. union cvmx_l2t_err l2t_err;
  135. union cvmx_l2d_err l2d_err;
  136. l2t_err.u64 = cvmx_read_csr(CVMX_L2T_ERR);
  137. l2t_err.s.sec_intena = 0; /* We poll */
  138. l2t_err.s.ded_intena = 0;
  139. cvmx_write_csr(CVMX_L2T_ERR, l2t_err.u64);
  140. l2d_err.u64 = cvmx_read_csr(CVMX_L2D_ERR);
  141. l2d_err.s.sec_intena = 0; /* We poll */
  142. l2d_err.s.ded_intena = 0;
  143. cvmx_write_csr(CVMX_L2T_ERR, l2d_err.u64);
  144. l2c->edac_check = octeon_l2c_poll_oct1;
  145. } else {
  146. /* OCTEON II */
  147. l2c->edac_check = octeon_l2c_poll_oct2;
  148. }
  149. if (edac_device_add_device(l2c) > 0) {
  150. pr_err("%s: edac_device_add_device() failed\n", __func__);
  151. goto err;
  152. }
  153. return 0;
  154. err:
  155. edac_device_free_ctl_info(l2c);
  156. return -ENXIO;
  157. }
  158. static int octeon_l2c_remove(struct platform_device *pdev)
  159. {
  160. struct edac_device_ctl_info *l2c = platform_get_drvdata(pdev);
  161. edac_device_del_device(&pdev->dev);
  162. edac_device_free_ctl_info(l2c);
  163. return 0;
  164. }
  165. static struct platform_driver octeon_l2c_driver = {
  166. .probe = octeon_l2c_probe,
  167. .remove = octeon_l2c_remove,
  168. .driver = {
  169. .name = "octeon_l2c_edac",
  170. }
  171. };
  172. module_platform_driver(octeon_l2c_driver);
  173. MODULE_LICENSE("GPL");
  174. MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");