fsl-corenet-cf.c 6.1 KB

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