cell_edac.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 dimm_info *dimm;
  112. struct cell_edac_priv *priv = mci->pvt_info;
  113. struct device_node *np;
  114. int j;
  115. for (np = NULL;
  116. (np = of_find_node_by_name(np, "memory")) != NULL;) {
  117. struct resource r;
  118. /* We "know" that the Cell firmware only creates one entry
  119. * in the "memory" nodes. If that changes, this code will
  120. * need to be adapted.
  121. */
  122. if (of_address_to_resource(np, 0, &r))
  123. continue;
  124. if (of_node_to_nid(np) != priv->node)
  125. continue;
  126. csrow->first_page = r.start >> PAGE_SHIFT;
  127. csrow->nr_pages = resource_size(&r) >> PAGE_SHIFT;
  128. csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
  129. for (j = 0; j < csrow->nr_channels; j++) {
  130. dimm = csrow->channels[j].dimm;
  131. dimm->mtype = MEM_XDR;
  132. dimm->edac_mode = EDAC_SECDED;
  133. }
  134. dev_dbg(mci->dev,
  135. "Initialized on node %d, chanmask=0x%x,"
  136. " first_page=0x%lx, nr_pages=0x%x\n",
  137. priv->node, priv->chanmask,
  138. csrow->first_page, csrow->nr_pages);
  139. break;
  140. }
  141. }
  142. static int __devinit cell_edac_probe(struct platform_device *pdev)
  143. {
  144. struct cbe_mic_tm_regs __iomem *regs;
  145. struct mem_ctl_info *mci;
  146. struct cell_edac_priv *priv;
  147. u64 reg;
  148. int rc, chanmask;
  149. regs = cbe_get_cpu_mic_tm_regs(cbe_node_to_cpu(pdev->id));
  150. if (regs == NULL)
  151. return -ENODEV;
  152. edac_op_state = EDAC_OPSTATE_POLL;
  153. /* Get channel population */
  154. reg = in_be64(&regs->mic_mnt_cfg);
  155. dev_dbg(&pdev->dev, "MIC_MNT_CFG = 0x%016llx\n", reg);
  156. chanmask = 0;
  157. if (reg & CBE_MIC_MNT_CFG_CHAN_0_POP)
  158. chanmask |= 0x1;
  159. if (reg & CBE_MIC_MNT_CFG_CHAN_1_POP)
  160. chanmask |= 0x2;
  161. if (chanmask == 0) {
  162. dev_warn(&pdev->dev,
  163. "Yuck ! No channel populated ? Aborting !\n");
  164. return -ENODEV;
  165. }
  166. dev_dbg(&pdev->dev, "Initial FIR = 0x%016llx\n",
  167. in_be64(&regs->mic_fir));
  168. /* Allocate & init EDAC MC data structure */
  169. mci = edac_mc_alloc(sizeof(struct cell_edac_priv), 1,
  170. chanmask == 3 ? 2 : 1, pdev->id);
  171. if (mci == NULL)
  172. return -ENOMEM;
  173. priv = mci->pvt_info;
  174. priv->regs = regs;
  175. priv->node = pdev->id;
  176. priv->chanmask = chanmask;
  177. mci->dev = &pdev->dev;
  178. mci->mtype_cap = MEM_FLAG_XDR;
  179. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
  180. mci->edac_cap = EDAC_FLAG_EC | EDAC_FLAG_SECDED;
  181. mci->mod_name = "cell_edac";
  182. mci->ctl_name = "MIC";
  183. mci->dev_name = dev_name(&pdev->dev);
  184. mci->edac_check = cell_edac_check;
  185. cell_edac_init_csrows(mci);
  186. /* Register with EDAC core */
  187. rc = edac_mc_add_mc(mci);
  188. if (rc) {
  189. dev_err(&pdev->dev, "failed to register with EDAC core\n");
  190. edac_mc_free(mci);
  191. return rc;
  192. }
  193. return 0;
  194. }
  195. static int __devexit cell_edac_remove(struct platform_device *pdev)
  196. {
  197. struct mem_ctl_info *mci = edac_mc_del_mc(&pdev->dev);
  198. if (mci)
  199. edac_mc_free(mci);
  200. return 0;
  201. }
  202. static struct platform_driver cell_edac_driver = {
  203. .driver = {
  204. .name = "cbe-mic",
  205. .owner = THIS_MODULE,
  206. },
  207. .probe = cell_edac_probe,
  208. .remove = __devexit_p(cell_edac_remove),
  209. };
  210. static int __init cell_edac_init(void)
  211. {
  212. /* Sanity check registers data structure */
  213. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  214. mic_df_ecc_address_0) != 0xf8);
  215. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  216. mic_df_ecc_address_1) != 0x1b8);
  217. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  218. mic_df_config) != 0x218);
  219. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  220. mic_fir) != 0x230);
  221. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  222. mic_mnt_cfg) != 0x210);
  223. BUILD_BUG_ON(offsetof(struct cbe_mic_tm_regs,
  224. mic_exc) != 0x208);
  225. return platform_driver_register(&cell_edac_driver);
  226. }
  227. static void __exit cell_edac_exit(void)
  228. {
  229. platform_driver_unregister(&cell_edac_driver);
  230. }
  231. module_init(cell_edac_init);
  232. module_exit(cell_edac_exit);
  233. MODULE_LICENSE("GPL");
  234. MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
  235. MODULE_DESCRIPTION("ECC counting for Cell MIC");