octeon_edac-l2c.c 5.3 KB

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