cell_edac.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Cell MIC driver for ECC counting
  3. *
  4. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  5. * <benh@kernel.crashing.org>
  6. *
  7. * This file may be distributed under the terms of the
  8. * GNU General Public License.
  9. */
  10. #undef DEBUG
  11. #include <linux/edac.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/stop_machine.h>
  16. #include <linux/io.h>
  17. #include <asm/machdep.h>
  18. #include <asm/cell-regs.h>
  19. #include "edac_core.h"
  20. struct cell_edac_priv
  21. {
  22. struct cbe_mic_tm_regs __iomem *regs;
  23. int node;
  24. int chanmask;
  25. #ifdef DEBUG
  26. u64 prev_fir;
  27. #endif
  28. };
  29. static void cell_edac_count_ce(struct mem_ctl_info *mci, int chan, u64 ar)
  30. {
  31. struct cell_edac_priv *priv = mci->pvt_info;
  32. struct csrow_info *csrow = &mci->csrows[0];
  33. unsigned long address, pfn, offset, syndrome;
  34. dev_dbg(mci->dev, "ECC CE err on node %d, channel %d, ar = 0x%016llx\n",
  35. priv->node, chan, ar);
  36. /* Address decoding is likely a bit bogus, to dbl check */
  37. address = (ar & 0xffffffffe0000000ul) >> 29;
  38. if (priv->chanmask == 0x3)
  39. address = (address << 1) | chan;
  40. pfn = address >> PAGE_SHIFT;
  41. offset = address & ~PAGE_MASK;
  42. syndrome = (ar & 0x000000001fe00000ul) >> 21;
  43. /* TODO: Decoding of the error address */
  44. edac_mc_handle_ce(mci, csrow->first_page + pfn, offset,
  45. syndrome, 0, chan, "");
  46. }
  47. static void cell_edac_count_ue(struct mem_ctl_info *mci, int chan, u64 ar)
  48. {
  49. struct cell_edac_priv *priv = mci->pvt_info;
  50. struct csrow_info *csrow = &mci->csrows[0];
  51. unsigned long address, pfn, offset;
  52. dev_dbg(mci->dev, "ECC UE err on node %d, channel %d, ar = 0x%016llx\n",
  53. priv->node, chan, ar);
  54. /* Address decoding is likely a bit bogus, to dbl check */
  55. address = (ar & 0xffffffffe0000000ul) >> 29;
  56. if (priv->chanmask == 0x3)
  57. address = (address << 1) | chan;
  58. pfn = address >> PAGE_SHIFT;
  59. offset = address & ~PAGE_MASK;
  60. /* TODO: Decoding of the error address */
  61. edac_mc_handle_ue(mci, csrow->first_page + pfn, offset, 0, "");
  62. }
  63. static void cell_edac_check(struct mem_ctl_info *mci)
  64. {
  65. struct cell_edac_priv *priv = mci->pvt_info;
  66. u64 fir, addreg, clear = 0;
  67. fir = in_be64(&priv->regs->mic_fir);
  68. #ifdef DEBUG
  69. if (fir != priv->prev_fir) {
  70. dev_dbg(mci->dev, "fir change : 0x%016lx\n", fir);
  71. priv->prev_fir = fir;
  72. }
  73. #endif
  74. if ((priv->chanmask & 0x1) && (fir & CBE_MIC_FIR_ECC_SINGLE_0_ERR)) {
  75. addreg = in_be64(&priv->regs->mic_df_ecc_address_0);
  76. clear |= CBE_MIC_FIR_ECC_SINGLE_0_RESET;
  77. cell_edac_count_ce(mci, 0, addreg);
  78. }
  79. if ((priv->chanmask & 0x2) && (fir & CBE_MIC_FIR_ECC_SINGLE_1_ERR)) {
  80. addreg = in_be64(&priv->regs->mic_df_ecc_address_1);
  81. clear |= CBE_MIC_FIR_ECC_SINGLE_1_RESET;
  82. cell_edac_count_ce(mci, 1, addreg);
  83. }
  84. if ((priv->chanmask & 0x1) && (fir & CBE_MIC_FIR_ECC_MULTI_0_ERR)) {
  85. addreg = in_be64(&priv->regs->mic_df_ecc_address_0);
  86. clear |= CBE_MIC_FIR_ECC_MULTI_0_RESET;
  87. cell_edac_count_ue(mci, 0, addreg);
  88. }
  89. if ((priv->chanmask & 0x2) && (fir & CBE_MIC_FIR_ECC_MULTI_1_ERR)) {
  90. addreg = in_be64(&priv->regs->mic_df_ecc_address_1);
  91. clear |= CBE_MIC_FIR_ECC_MULTI_1_RESET;
  92. cell_edac_count_ue(mci, 1, addreg);
  93. }
  94. /* The procedure for clearing FIR bits is a bit ... weird */
  95. if (clear) {
  96. fir &= ~(CBE_MIC_FIR_ECC_ERR_MASK | CBE_MIC_FIR_ECC_SET_MASK);
  97. fir |= CBE_MIC_FIR_ECC_RESET_MASK;
  98. fir &= ~clear;
  99. out_be64(&priv->regs->mic_fir, fir);
  100. (void)in_be64(&priv->regs->mic_fir);
  101. mb(); /* sync up */
  102. #ifdef DEBUG
  103. fir = in_be64(&priv->regs->mic_fir);
  104. dev_dbg(mci->dev, "fir clear : 0x%016lx\n", fir);
  105. #endif
  106. }
  107. }
  108. static void __devinit cell_edac_init_csrows(struct mem_ctl_info *mci)
  109. {
  110. struct csrow_info *csrow = &mci->csrows[0];
  111. struct cell_edac_priv *priv = mci->pvt_info;
  112. struct device_node *np;
  113. for (np = NULL;
  114. (np = of_find_node_by_name(np, "memory")) != NULL;) {
  115. struct resource r;
  116. /* We "know" that the Cell firmware only creates one entry
  117. * in the "memory" nodes. If that changes, this code will
  118. * need to be adapted.
  119. */
  120. if (of_address_to_resource(np, 0, &r))
  121. continue;
  122. if (of_node_to_nid(np) != priv->node)
  123. continue;
  124. csrow->first_page = r.start >> PAGE_SHIFT;
  125. csrow->nr_pages = (r.end - r.start + 1) >> PAGE_SHIFT;
  126. csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
  127. csrow->mtype = MEM_XDR;
  128. csrow->edac_mode = EDAC_SECDED;
  129. dev_dbg(mci->dev,
  130. "Initialized on node %d, chanmask=0x%x,"
  131. " first_page=0x%lx, nr_pages=0x%x\n",
  132. priv->node, priv->chanmask,
  133. csrow->first_page, csrow->nr_pages);
  134. break;
  135. }
  136. }
  137. static int __devinit cell_edac_probe(struct platform_device *pdev)
  138. {
  139. struct cbe_mic_tm_regs __iomem *regs;
  140. struct mem_ctl_info *mci;
  141. struct cell_edac_priv *priv;
  142. u64 reg;
  143. int rc, chanmask;
  144. regs = cbe_get_cpu_mic_tm_regs(cbe_node_to_cpu(pdev->id));
  145. if (regs == NULL)
  146. return -ENODEV;
  147. edac_op_state = EDAC_OPSTATE_POLL;
  148. /* Get channel population */
  149. reg = in_be64(&regs->mic_mnt_cfg);
  150. dev_dbg(&pdev->dev, "MIC_MNT_CFG = 0x%016llx\n", reg);
  151. chanmask = 0;
  152. if (reg & CBE_MIC_MNT_CFG_CHAN_0_POP)
  153. chanmask |= 0x1;
  154. if (reg & CBE_MIC_MNT_CFG_CHAN_1_POP)
  155. chanmask |= 0x2;
  156. if (chanmask == 0) {
  157. dev_warn(&pdev->dev,
  158. "Yuck ! No channel populated ? Aborting !\n");
  159. return -ENODEV;
  160. }
  161. dev_dbg(&pdev->dev, "Initial FIR = 0x%016llx\n",
  162. in_be64(&regs->mic_fir));
  163. /* Allocate & init EDAC MC data structure */
  164. mci = edac_mc_alloc(sizeof(struct cell_edac_priv), 1,
  165. chanmask == 3 ? 2 : 1, pdev->id);
  166. if (mci == NULL)
  167. return -ENOMEM;
  168. priv = mci->pvt_info;
  169. priv->regs = regs;
  170. priv->node = pdev->id;
  171. priv->chanmask = chanmask;
  172. mci->dev = &pdev->dev;
  173. mci->mtype_cap = MEM_FLAG_XDR;
  174. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
  175. mci->edac_cap = EDAC_FLAG_EC | EDAC_FLAG_SECDED;
  176. mci->mod_name = "cell_edac";
  177. mci->ctl_name = "MIC";
  178. mci->dev_name = dev_name(&pdev->dev);
  179. mci->edac_check = cell_edac_check;
  180. cell_edac_init_csrows(mci);
  181. /* Register with EDAC core */
  182. rc = edac_mc_add_mc(mci);
  183. if (rc) {
  184. dev_err(&pdev->dev, "failed to register with EDAC core\n");
  185. edac_mc_free(mci);
  186. return rc;
  187. }
  188. return 0;
  189. }
  190. static int __devexit cell_edac_remove(struct platform_device *pdev)
  191. {
  192. struct mem_ctl_info *mci = edac_mc_del_mc(&pdev->dev);
  193. if (mci)
  194. edac_mc_free(mci);
  195. return 0;
  196. }
  197. static struct platform_driver cell_edac_driver = {
  198. .driver = {
  199. .name = "cbe-mic",
  200. .owner = THIS_MODULE,
  201. },
  202. .probe = cell_edac_probe,
  203. .remove = __devexit_p(cell_edac_remove),
  204. };
  205. static int __init cell_edac_init(void)
  206. {
  207. /* Sanity check registers data structure */
  208. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  209. mic_df_ecc_address_0) != 0xf8);
  210. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  211. mic_df_ecc_address_1) != 0x1b8);
  212. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  213. mic_df_config) != 0x218);
  214. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  215. mic_fir) != 0x230);
  216. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  217. mic_mnt_cfg) != 0x210);
  218. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  219. mic_exc) != 0x208);
  220. return platform_driver_register(&cell_edac_driver);
  221. }
  222. static void __exit cell_edac_exit(void)
  223. {
  224. platform_driver_unregister(&cell_edac_driver);
  225. }
  226. module_init(cell_edac_init);
  227. module_exit(cell_edac_exit);
  228. MODULE_LICENSE("GPL");
  229. MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
  230. MODULE_DESCRIPTION("ECC counting for Cell MIC");