cell_edac.c 7.2 KB

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