cell_edac.c 7.1 KB

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