fsl-corenet-cf.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * CoreNet Coherency Fabric error reporting
  3. *
  4. * Copyright 2014 Freescale Semiconductor Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/io.h>
  13. #include <linux/irq.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_device.h>
  18. #include <linux/of_irq.h>
  19. #include <linux/platform_device.h>
  20. enum ccf_version {
  21. CCF1,
  22. CCF2,
  23. };
  24. struct ccf_info {
  25. enum ccf_version version;
  26. int err_reg_offs;
  27. bool has_brr;
  28. };
  29. static const struct ccf_info ccf1_info = {
  30. .version = CCF1,
  31. .err_reg_offs = 0xa00,
  32. .has_brr = false,
  33. };
  34. static const struct ccf_info ccf2_info = {
  35. .version = CCF2,
  36. .err_reg_offs = 0xe40,
  37. .has_brr = true,
  38. };
  39. /*
  40. * This register is present but not documented, with different values for
  41. * IP_ID, on other chips with fsl,corenet2-cf such as t4240 and b4860.
  42. */
  43. #define CCF_BRR 0xbf8
  44. #define CCF_BRR_IPID 0xffff0000
  45. #define CCF_BRR_IPID_T1040 0x09310000
  46. static const struct of_device_id ccf_matches[] = {
  47. {
  48. .compatible = "fsl,corenet1-cf",
  49. .data = &ccf1_info,
  50. },
  51. {
  52. .compatible = "fsl,corenet2-cf",
  53. .data = &ccf2_info,
  54. },
  55. {}
  56. };
  57. MODULE_DEVICE_TABLE(of, ccf_matches);
  58. struct ccf_err_regs {
  59. u32 errdet; /* 0x00 Error Detect Register */
  60. /* 0x04 Error Enable (ccf1)/Disable (ccf2) Register */
  61. u32 errdis;
  62. /* 0x08 Error Interrupt Enable Register (ccf2 only) */
  63. u32 errinten;
  64. u32 cecar; /* 0x0c Error Capture Attribute Register */
  65. u32 cecaddrh; /* 0x10 Error Capture Address High */
  66. u32 cecaddrl; /* 0x14 Error Capture Address Low */
  67. u32 cecar2; /* 0x18 Error Capture Attribute Register 2 */
  68. };
  69. /* LAE/CV also valid for errdis and errinten */
  70. #define ERRDET_LAE (1 << 0) /* Local Access Error */
  71. #define ERRDET_CV (1 << 1) /* Coherency Violation */
  72. #define ERRDET_UTID (1 << 2) /* Unavailable Target ID (t1040) */
  73. #define ERRDET_MCST (1 << 3) /* Multicast Stash (t1040) */
  74. #define ERRDET_CTYPE_SHIFT 26 /* Capture Type (ccf2 only) */
  75. #define ERRDET_CTYPE_MASK (0x1f << ERRDET_CTYPE_SHIFT)
  76. #define ERRDET_CAP (1 << 31) /* Capture Valid (ccf2 only) */
  77. #define CECAR_VAL (1 << 0) /* Valid (ccf1 only) */
  78. #define CECAR_UVT (1 << 15) /* Unavailable target ID (ccf1) */
  79. #define CECAR_SRCID_SHIFT_CCF1 24
  80. #define CECAR_SRCID_MASK_CCF1 (0xff << CECAR_SRCID_SHIFT_CCF1)
  81. #define CECAR_SRCID_SHIFT_CCF2 18
  82. #define CECAR_SRCID_MASK_CCF2 (0xff << CECAR_SRCID_SHIFT_CCF2)
  83. #define CECADDRH_ADDRH 0xff
  84. struct ccf_private {
  85. const struct ccf_info *info;
  86. struct device *dev;
  87. void __iomem *regs;
  88. struct ccf_err_regs __iomem *err_regs;
  89. bool t1040;
  90. };
  91. static irqreturn_t ccf_irq(int irq, void *dev_id)
  92. {
  93. struct ccf_private *ccf = dev_id;
  94. static DEFINE_RATELIMIT_STATE(ratelimit, DEFAULT_RATELIMIT_INTERVAL,
  95. DEFAULT_RATELIMIT_BURST);
  96. u32 errdet, cecar, cecar2;
  97. u64 addr;
  98. u32 src_id;
  99. bool uvt = false;
  100. bool cap_valid = false;
  101. errdet = ioread32be(&ccf->err_regs->errdet);
  102. cecar = ioread32be(&ccf->err_regs->cecar);
  103. cecar2 = ioread32be(&ccf->err_regs->cecar2);
  104. addr = ioread32be(&ccf->err_regs->cecaddrl);
  105. addr |= ((u64)(ioread32be(&ccf->err_regs->cecaddrh) &
  106. CECADDRH_ADDRH)) << 32;
  107. if (!__ratelimit(&ratelimit))
  108. goto out;
  109. switch (ccf->info->version) {
  110. case CCF1:
  111. if (cecar & CECAR_VAL) {
  112. if (cecar & CECAR_UVT)
  113. uvt = true;
  114. src_id = (cecar & CECAR_SRCID_MASK_CCF1) >>
  115. CECAR_SRCID_SHIFT_CCF1;
  116. cap_valid = true;
  117. }
  118. break;
  119. case CCF2:
  120. if (errdet & ERRDET_CAP) {
  121. src_id = (cecar & CECAR_SRCID_MASK_CCF2) >>
  122. CECAR_SRCID_SHIFT_CCF2;
  123. cap_valid = true;
  124. }
  125. break;
  126. }
  127. dev_crit(ccf->dev, "errdet 0x%08x cecar 0x%08x cecar2 0x%08x\n",
  128. errdet, cecar, cecar2);
  129. if (errdet & ERRDET_LAE) {
  130. if (uvt)
  131. dev_crit(ccf->dev, "LAW Unavailable Target ID\n");
  132. else
  133. dev_crit(ccf->dev, "Local Access Window Error\n");
  134. }
  135. if (errdet & ERRDET_CV)
  136. dev_crit(ccf->dev, "Coherency Violation\n");
  137. if (errdet & ERRDET_UTID)
  138. dev_crit(ccf->dev, "Unavailable Target ID\n");
  139. if (errdet & ERRDET_MCST)
  140. dev_crit(ccf->dev, "Multicast Stash\n");
  141. if (cap_valid) {
  142. dev_crit(ccf->dev, "address 0x%09llx, src id 0x%x\n",
  143. addr, src_id);
  144. }
  145. out:
  146. iowrite32be(errdet, &ccf->err_regs->errdet);
  147. return errdet ? IRQ_HANDLED : IRQ_NONE;
  148. }
  149. static int ccf_probe(struct platform_device *pdev)
  150. {
  151. struct ccf_private *ccf;
  152. struct resource *r;
  153. const struct of_device_id *match;
  154. u32 errinten;
  155. int ret, irq;
  156. match = of_match_device(ccf_matches, &pdev->dev);
  157. if (WARN_ON(!match))
  158. return -ENODEV;
  159. ccf = devm_kzalloc(&pdev->dev, sizeof(*ccf), GFP_KERNEL);
  160. if (!ccf)
  161. return -ENOMEM;
  162. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  163. if (!r) {
  164. dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
  165. return -ENXIO;
  166. }
  167. ccf->regs = devm_ioremap_resource(&pdev->dev, r);
  168. if (IS_ERR(ccf->regs)) {
  169. dev_err(&pdev->dev, "%s: can't map mem resource\n", __func__);
  170. return PTR_ERR(ccf->regs);
  171. }
  172. ccf->dev = &pdev->dev;
  173. ccf->info = match->data;
  174. ccf->err_regs = ccf->regs + ccf->info->err_reg_offs;
  175. if (ccf->info->has_brr) {
  176. u32 brr = ioread32be(ccf->regs + CCF_BRR);
  177. if ((brr & CCF_BRR_IPID) == CCF_BRR_IPID_T1040)
  178. ccf->t1040 = true;
  179. }
  180. dev_set_drvdata(&pdev->dev, ccf);
  181. irq = platform_get_irq(pdev, 0);
  182. if (irq < 0)
  183. return irq;
  184. ret = devm_request_irq(&pdev->dev, irq, ccf_irq, 0, pdev->name, ccf);
  185. if (ret) {
  186. dev_err(&pdev->dev, "%s: can't request irq\n", __func__);
  187. return ret;
  188. }
  189. errinten = ERRDET_LAE | ERRDET_CV;
  190. if (ccf->t1040)
  191. errinten |= ERRDET_UTID | ERRDET_MCST;
  192. switch (ccf->info->version) {
  193. case CCF1:
  194. /* On CCF1 this register enables rather than disables. */
  195. iowrite32be(errinten, &ccf->err_regs->errdis);
  196. break;
  197. case CCF2:
  198. iowrite32be(0, &ccf->err_regs->errdis);
  199. iowrite32be(errinten, &ccf->err_regs->errinten);
  200. break;
  201. }
  202. return 0;
  203. }
  204. static int ccf_remove(struct platform_device *pdev)
  205. {
  206. struct ccf_private *ccf = dev_get_drvdata(&pdev->dev);
  207. switch (ccf->info->version) {
  208. case CCF1:
  209. iowrite32be(0, &ccf->err_regs->errdis);
  210. break;
  211. case CCF2:
  212. /*
  213. * We clear errdis on ccf1 because that's the only way to
  214. * disable interrupts, but on ccf2 there's no need to disable
  215. * detection.
  216. */
  217. iowrite32be(0, &ccf->err_regs->errinten);
  218. break;
  219. }
  220. return 0;
  221. }
  222. static struct platform_driver ccf_driver = {
  223. .driver = {
  224. .name = KBUILD_MODNAME,
  225. .of_match_table = ccf_matches,
  226. },
  227. .probe = ccf_probe,
  228. .remove = ccf_remove,
  229. };
  230. module_platform_driver(ccf_driver);
  231. MODULE_LICENSE("GPL");
  232. MODULE_AUTHOR("Freescale Semiconductor");
  233. MODULE_DESCRIPTION("Freescale CoreNet Coherency Fabric error reporting");