xgene_edac.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. * APM X-Gene SoC EDAC (error detection and correction)
  3. *
  4. * Copyright (c) 2015, Applied Micro Circuits Corporation
  5. * Author: Feng Kan <fkan@apm.com>
  6. * Loc Ho <lho@apm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/ctype.h>
  22. #include <linux/edac.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/mfd/syscon.h>
  25. #include <linux/module.h>
  26. #include <linux/of.h>
  27. #include <linux/of_address.h>
  28. #include <linux/regmap.h>
  29. #include "edac_core.h"
  30. #define EDAC_MOD_STR "xgene_edac"
  31. /* Global error configuration status registers (CSR) */
  32. #define PCPHPERRINTSTS 0x0000
  33. #define PCPHPERRINTMSK 0x0004
  34. #define MCU_CTL_ERR_MASK BIT(12)
  35. #define IOB_PA_ERR_MASK BIT(11)
  36. #define IOB_BA_ERR_MASK BIT(10)
  37. #define IOB_XGIC_ERR_MASK BIT(9)
  38. #define IOB_RB_ERR_MASK BIT(8)
  39. #define L3C_UNCORR_ERR_MASK BIT(5)
  40. #define MCU_UNCORR_ERR_MASK BIT(4)
  41. #define PMD3_MERR_MASK BIT(3)
  42. #define PMD2_MERR_MASK BIT(2)
  43. #define PMD1_MERR_MASK BIT(1)
  44. #define PMD0_MERR_MASK BIT(0)
  45. #define PCPLPERRINTSTS 0x0008
  46. #define PCPLPERRINTMSK 0x000C
  47. #define CSW_SWITCH_TRACE_ERR_MASK BIT(2)
  48. #define L3C_CORR_ERR_MASK BIT(1)
  49. #define MCU_CORR_ERR_MASK BIT(0)
  50. #define MEMERRINTSTS 0x0010
  51. #define MEMERRINTMSK 0x0014
  52. struct xgene_edac {
  53. struct device *dev;
  54. struct regmap *csw_map;
  55. struct regmap *mcba_map;
  56. struct regmap *mcbb_map;
  57. struct regmap *efuse_map;
  58. void __iomem *pcp_csr;
  59. spinlock_t lock;
  60. struct dentry *dfs;
  61. struct list_head mcus;
  62. struct list_head pmds;
  63. struct mutex mc_lock;
  64. int mc_active_mask;
  65. int mc_registered_mask;
  66. };
  67. static void xgene_edac_pcp_rd(struct xgene_edac *edac, u32 reg, u32 *val)
  68. {
  69. *val = readl(edac->pcp_csr + reg);
  70. }
  71. static void xgene_edac_pcp_clrbits(struct xgene_edac *edac, u32 reg,
  72. u32 bits_mask)
  73. {
  74. u32 val;
  75. spin_lock(&edac->lock);
  76. val = readl(edac->pcp_csr + reg);
  77. val &= ~bits_mask;
  78. writel(val, edac->pcp_csr + reg);
  79. spin_unlock(&edac->lock);
  80. }
  81. static void xgene_edac_pcp_setbits(struct xgene_edac *edac, u32 reg,
  82. u32 bits_mask)
  83. {
  84. u32 val;
  85. spin_lock(&edac->lock);
  86. val = readl(edac->pcp_csr + reg);
  87. val |= bits_mask;
  88. writel(val, edac->pcp_csr + reg);
  89. spin_unlock(&edac->lock);
  90. }
  91. /* Memory controller error CSR */
  92. #define MCU_MAX_RANK 8
  93. #define MCU_RANK_STRIDE 0x40
  94. #define MCUGECR 0x0110
  95. #define MCU_GECR_DEMANDUCINTREN_MASK BIT(0)
  96. #define MCU_GECR_BACKUCINTREN_MASK BIT(1)
  97. #define MCU_GECR_CINTREN_MASK BIT(2)
  98. #define MUC_GECR_MCUADDRERREN_MASK BIT(9)
  99. #define MCUGESR 0x0114
  100. #define MCU_GESR_ADDRNOMATCH_ERR_MASK BIT(7)
  101. #define MCU_GESR_ADDRMULTIMATCH_ERR_MASK BIT(6)
  102. #define MCU_GESR_PHYP_ERR_MASK BIT(3)
  103. #define MCUESRR0 0x0314
  104. #define MCU_ESRR_MULTUCERR_MASK BIT(3)
  105. #define MCU_ESRR_BACKUCERR_MASK BIT(2)
  106. #define MCU_ESRR_DEMANDUCERR_MASK BIT(1)
  107. #define MCU_ESRR_CERR_MASK BIT(0)
  108. #define MCUESRRA0 0x0318
  109. #define MCUEBLRR0 0x031c
  110. #define MCU_EBLRR_ERRBANK_RD(src) (((src) & 0x00000007) >> 0)
  111. #define MCUERCRR0 0x0320
  112. #define MCU_ERCRR_ERRROW_RD(src) (((src) & 0xFFFF0000) >> 16)
  113. #define MCU_ERCRR_ERRCOL_RD(src) ((src) & 0x00000FFF)
  114. #define MCUSBECNT0 0x0324
  115. #define MCU_SBECNT_COUNT(src) ((src) & 0xFFFF)
  116. #define CSW_CSWCR 0x0000
  117. #define CSW_CSWCR_DUALMCB_MASK BIT(0)
  118. #define MCBADDRMR 0x0000
  119. #define MCBADDRMR_MCU_INTLV_MODE_MASK BIT(3)
  120. #define MCBADDRMR_DUALMCU_MODE_MASK BIT(2)
  121. #define MCBADDRMR_MCB_INTLV_MODE_MASK BIT(1)
  122. #define MCBADDRMR_ADDRESS_MODE_MASK BIT(0)
  123. struct xgene_edac_mc_ctx {
  124. struct list_head next;
  125. char *name;
  126. struct mem_ctl_info *mci;
  127. struct xgene_edac *edac;
  128. void __iomem *mcu_csr;
  129. u32 mcu_id;
  130. };
  131. static ssize_t xgene_edac_mc_err_inject_write(struct file *file,
  132. const char __user *data,
  133. size_t count, loff_t *ppos)
  134. {
  135. struct mem_ctl_info *mci = file->private_data;
  136. struct xgene_edac_mc_ctx *ctx = mci->pvt_info;
  137. int i;
  138. for (i = 0; i < MCU_MAX_RANK; i++) {
  139. writel(MCU_ESRR_MULTUCERR_MASK | MCU_ESRR_BACKUCERR_MASK |
  140. MCU_ESRR_DEMANDUCERR_MASK | MCU_ESRR_CERR_MASK,
  141. ctx->mcu_csr + MCUESRRA0 + i * MCU_RANK_STRIDE);
  142. }
  143. return count;
  144. }
  145. static const struct file_operations xgene_edac_mc_debug_inject_fops = {
  146. .open = simple_open,
  147. .write = xgene_edac_mc_err_inject_write,
  148. .llseek = generic_file_llseek,
  149. };
  150. static void xgene_edac_mc_create_debugfs_node(struct mem_ctl_info *mci)
  151. {
  152. if (!IS_ENABLED(CONFIG_EDAC_DEBUG))
  153. return;
  154. #ifdef CONFIG_EDAC_DEBUG
  155. if (!mci->debugfs)
  156. return;
  157. debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci,
  158. &xgene_edac_mc_debug_inject_fops);
  159. #endif
  160. }
  161. static void xgene_edac_mc_check(struct mem_ctl_info *mci)
  162. {
  163. struct xgene_edac_mc_ctx *ctx = mci->pvt_info;
  164. unsigned int pcp_hp_stat;
  165. unsigned int pcp_lp_stat;
  166. u32 reg;
  167. u32 rank;
  168. u32 bank;
  169. u32 count;
  170. u32 col_row;
  171. xgene_edac_pcp_rd(ctx->edac, PCPHPERRINTSTS, &pcp_hp_stat);
  172. xgene_edac_pcp_rd(ctx->edac, PCPLPERRINTSTS, &pcp_lp_stat);
  173. if (!((MCU_UNCORR_ERR_MASK & pcp_hp_stat) ||
  174. (MCU_CTL_ERR_MASK & pcp_hp_stat) ||
  175. (MCU_CORR_ERR_MASK & pcp_lp_stat)))
  176. return;
  177. for (rank = 0; rank < MCU_MAX_RANK; rank++) {
  178. reg = readl(ctx->mcu_csr + MCUESRR0 + rank * MCU_RANK_STRIDE);
  179. /* Detect uncorrectable memory error */
  180. if (reg & (MCU_ESRR_DEMANDUCERR_MASK |
  181. MCU_ESRR_BACKUCERR_MASK)) {
  182. /* Detected uncorrectable memory error */
  183. edac_mc_chipset_printk(mci, KERN_ERR, "X-Gene",
  184. "MCU uncorrectable error at rank %d\n", rank);
  185. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci,
  186. 1, 0, 0, 0, 0, 0, -1, mci->ctl_name, "");
  187. }
  188. /* Detect correctable memory error */
  189. if (reg & MCU_ESRR_CERR_MASK) {
  190. bank = readl(ctx->mcu_csr + MCUEBLRR0 +
  191. rank * MCU_RANK_STRIDE);
  192. col_row = readl(ctx->mcu_csr + MCUERCRR0 +
  193. rank * MCU_RANK_STRIDE);
  194. count = readl(ctx->mcu_csr + MCUSBECNT0 +
  195. rank * MCU_RANK_STRIDE);
  196. edac_mc_chipset_printk(mci, KERN_WARNING, "X-Gene",
  197. "MCU correctable error at rank %d bank %d column %d row %d count %d\n",
  198. rank, MCU_EBLRR_ERRBANK_RD(bank),
  199. MCU_ERCRR_ERRCOL_RD(col_row),
  200. MCU_ERCRR_ERRROW_RD(col_row),
  201. MCU_SBECNT_COUNT(count));
  202. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci,
  203. 1, 0, 0, 0, 0, 0, -1, mci->ctl_name, "");
  204. }
  205. /* Clear all error registers */
  206. writel(0x0, ctx->mcu_csr + MCUEBLRR0 + rank * MCU_RANK_STRIDE);
  207. writel(0x0, ctx->mcu_csr + MCUERCRR0 + rank * MCU_RANK_STRIDE);
  208. writel(0x0, ctx->mcu_csr + MCUSBECNT0 +
  209. rank * MCU_RANK_STRIDE);
  210. writel(reg, ctx->mcu_csr + MCUESRR0 + rank * MCU_RANK_STRIDE);
  211. }
  212. /* Detect memory controller error */
  213. reg = readl(ctx->mcu_csr + MCUGESR);
  214. if (reg) {
  215. if (reg & MCU_GESR_ADDRNOMATCH_ERR_MASK)
  216. edac_mc_chipset_printk(mci, KERN_WARNING, "X-Gene",
  217. "MCU address miss-match error\n");
  218. if (reg & MCU_GESR_ADDRMULTIMATCH_ERR_MASK)
  219. edac_mc_chipset_printk(mci, KERN_WARNING, "X-Gene",
  220. "MCU address multi-match error\n");
  221. writel(reg, ctx->mcu_csr + MCUGESR);
  222. }
  223. }
  224. static void xgene_edac_mc_irq_ctl(struct mem_ctl_info *mci, bool enable)
  225. {
  226. struct xgene_edac_mc_ctx *ctx = mci->pvt_info;
  227. unsigned int val;
  228. if (edac_op_state != EDAC_OPSTATE_INT)
  229. return;
  230. mutex_lock(&ctx->edac->mc_lock);
  231. /*
  232. * As there is only single bit for enable error and interrupt mask,
  233. * we must only enable top level interrupt after all MCUs are
  234. * registered. Otherwise, if there is an error and the corresponding
  235. * MCU has not registered, the interrupt will never get cleared. To
  236. * determine all MCU have registered, we will keep track of active
  237. * MCUs and registered MCUs.
  238. */
  239. if (enable) {
  240. /* Set registered MCU bit */
  241. ctx->edac->mc_registered_mask |= 1 << ctx->mcu_id;
  242. /* Enable interrupt after all active MCU registered */
  243. if (ctx->edac->mc_registered_mask ==
  244. ctx->edac->mc_active_mask) {
  245. /* Enable memory controller top level interrupt */
  246. xgene_edac_pcp_clrbits(ctx->edac, PCPHPERRINTMSK,
  247. MCU_UNCORR_ERR_MASK |
  248. MCU_CTL_ERR_MASK);
  249. xgene_edac_pcp_clrbits(ctx->edac, PCPLPERRINTMSK,
  250. MCU_CORR_ERR_MASK);
  251. }
  252. /* Enable MCU interrupt and error reporting */
  253. val = readl(ctx->mcu_csr + MCUGECR);
  254. val |= MCU_GECR_DEMANDUCINTREN_MASK |
  255. MCU_GECR_BACKUCINTREN_MASK |
  256. MCU_GECR_CINTREN_MASK |
  257. MUC_GECR_MCUADDRERREN_MASK;
  258. writel(val, ctx->mcu_csr + MCUGECR);
  259. } else {
  260. /* Disable MCU interrupt */
  261. val = readl(ctx->mcu_csr + MCUGECR);
  262. val &= ~(MCU_GECR_DEMANDUCINTREN_MASK |
  263. MCU_GECR_BACKUCINTREN_MASK |
  264. MCU_GECR_CINTREN_MASK |
  265. MUC_GECR_MCUADDRERREN_MASK);
  266. writel(val, ctx->mcu_csr + MCUGECR);
  267. /* Disable memory controller top level interrupt */
  268. xgene_edac_pcp_setbits(ctx->edac, PCPHPERRINTMSK,
  269. MCU_UNCORR_ERR_MASK | MCU_CTL_ERR_MASK);
  270. xgene_edac_pcp_setbits(ctx->edac, PCPLPERRINTMSK,
  271. MCU_CORR_ERR_MASK);
  272. /* Clear registered MCU bit */
  273. ctx->edac->mc_registered_mask &= ~(1 << ctx->mcu_id);
  274. }
  275. mutex_unlock(&ctx->edac->mc_lock);
  276. }
  277. static int xgene_edac_mc_is_active(struct xgene_edac_mc_ctx *ctx, int mc_idx)
  278. {
  279. unsigned int reg;
  280. u32 mcu_mask;
  281. if (regmap_read(ctx->edac->csw_map, CSW_CSWCR, &reg))
  282. return 0;
  283. if (reg & CSW_CSWCR_DUALMCB_MASK) {
  284. /*
  285. * Dual MCB active - Determine if all 4 active or just MCU0
  286. * and MCU2 active
  287. */
  288. if (regmap_read(ctx->edac->mcbb_map, MCBADDRMR, &reg))
  289. return 0;
  290. mcu_mask = (reg & MCBADDRMR_DUALMCU_MODE_MASK) ? 0xF : 0x5;
  291. } else {
  292. /*
  293. * Single MCB active - Determine if MCU0/MCU1 or just MCU0
  294. * active
  295. */
  296. if (regmap_read(ctx->edac->mcba_map, MCBADDRMR, &reg))
  297. return 0;
  298. mcu_mask = (reg & MCBADDRMR_DUALMCU_MODE_MASK) ? 0x3 : 0x1;
  299. }
  300. /* Save active MC mask if hasn't set already */
  301. if (!ctx->edac->mc_active_mask)
  302. ctx->edac->mc_active_mask = mcu_mask;
  303. return (mcu_mask & (1 << mc_idx)) ? 1 : 0;
  304. }
  305. static int xgene_edac_mc_add(struct xgene_edac *edac, struct device_node *np)
  306. {
  307. struct mem_ctl_info *mci;
  308. struct edac_mc_layer layers[2];
  309. struct xgene_edac_mc_ctx tmp_ctx;
  310. struct xgene_edac_mc_ctx *ctx;
  311. struct resource res;
  312. int rc;
  313. memset(&tmp_ctx, 0, sizeof(tmp_ctx));
  314. tmp_ctx.edac = edac;
  315. if (!devres_open_group(edac->dev, xgene_edac_mc_add, GFP_KERNEL))
  316. return -ENOMEM;
  317. rc = of_address_to_resource(np, 0, &res);
  318. if (rc < 0) {
  319. dev_err(edac->dev, "no MCU resource address\n");
  320. goto err_group;
  321. }
  322. tmp_ctx.mcu_csr = devm_ioremap_resource(edac->dev, &res);
  323. if (IS_ERR(tmp_ctx.mcu_csr)) {
  324. dev_err(edac->dev, "unable to map MCU resource\n");
  325. rc = PTR_ERR(tmp_ctx.mcu_csr);
  326. goto err_group;
  327. }
  328. /* Ignore non-active MCU */
  329. if (of_property_read_u32(np, "memory-controller", &tmp_ctx.mcu_id)) {
  330. dev_err(edac->dev, "no memory-controller property\n");
  331. rc = -ENODEV;
  332. goto err_group;
  333. }
  334. if (!xgene_edac_mc_is_active(&tmp_ctx, tmp_ctx.mcu_id)) {
  335. rc = -ENODEV;
  336. goto err_group;
  337. }
  338. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  339. layers[0].size = 4;
  340. layers[0].is_virt_csrow = true;
  341. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  342. layers[1].size = 2;
  343. layers[1].is_virt_csrow = false;
  344. mci = edac_mc_alloc(tmp_ctx.mcu_id, ARRAY_SIZE(layers), layers,
  345. sizeof(*ctx));
  346. if (!mci) {
  347. rc = -ENOMEM;
  348. goto err_group;
  349. }
  350. ctx = mci->pvt_info;
  351. *ctx = tmp_ctx; /* Copy over resource value */
  352. ctx->name = "xgene_edac_mc_err";
  353. ctx->mci = mci;
  354. mci->pdev = &mci->dev;
  355. mci->ctl_name = ctx->name;
  356. mci->dev_name = ctx->name;
  357. mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_RDDR2 | MEM_FLAG_RDDR3 |
  358. MEM_FLAG_DDR | MEM_FLAG_DDR2 | MEM_FLAG_DDR3;
  359. mci->edac_ctl_cap = EDAC_FLAG_SECDED;
  360. mci->edac_cap = EDAC_FLAG_SECDED;
  361. mci->mod_name = EDAC_MOD_STR;
  362. mci->mod_ver = "0.1";
  363. mci->ctl_page_to_phys = NULL;
  364. mci->scrub_cap = SCRUB_FLAG_HW_SRC;
  365. mci->scrub_mode = SCRUB_HW_SRC;
  366. if (edac_op_state == EDAC_OPSTATE_POLL)
  367. mci->edac_check = xgene_edac_mc_check;
  368. if (edac_mc_add_mc(mci)) {
  369. dev_err(edac->dev, "edac_mc_add_mc failed\n");
  370. rc = -EINVAL;
  371. goto err_free;
  372. }
  373. xgene_edac_mc_create_debugfs_node(mci);
  374. list_add(&ctx->next, &edac->mcus);
  375. xgene_edac_mc_irq_ctl(mci, true);
  376. devres_remove_group(edac->dev, xgene_edac_mc_add);
  377. dev_info(edac->dev, "X-Gene EDAC MC registered\n");
  378. return 0;
  379. err_free:
  380. edac_mc_free(mci);
  381. err_group:
  382. devres_release_group(edac->dev, xgene_edac_mc_add);
  383. return rc;
  384. }
  385. static int xgene_edac_mc_remove(struct xgene_edac_mc_ctx *mcu)
  386. {
  387. xgene_edac_mc_irq_ctl(mcu->mci, false);
  388. edac_mc_del_mc(&mcu->mci->dev);
  389. edac_mc_free(mcu->mci);
  390. return 0;
  391. }
  392. /* CPU L1/L2 error CSR */
  393. #define MAX_CPU_PER_PMD 2
  394. #define CPU_CSR_STRIDE 0x00100000
  395. #define CPU_L2C_PAGE 0x000D0000
  396. #define CPU_MEMERR_L2C_PAGE 0x000E0000
  397. #define CPU_MEMERR_CPU_PAGE 0x000F0000
  398. #define MEMERR_CPU_ICFECR_PAGE_OFFSET 0x0000
  399. #define MEMERR_CPU_ICFESR_PAGE_OFFSET 0x0004
  400. #define MEMERR_CPU_ICFESR_ERRWAY_RD(src) (((src) & 0xFF000000) >> 24)
  401. #define MEMERR_CPU_ICFESR_ERRINDEX_RD(src) (((src) & 0x003F0000) >> 16)
  402. #define MEMERR_CPU_ICFESR_ERRINFO_RD(src) (((src) & 0x0000FF00) >> 8)
  403. #define MEMERR_CPU_ICFESR_ERRTYPE_RD(src) (((src) & 0x00000070) >> 4)
  404. #define MEMERR_CPU_ICFESR_MULTCERR_MASK BIT(2)
  405. #define MEMERR_CPU_ICFESR_CERR_MASK BIT(0)
  406. #define MEMERR_CPU_LSUESR_PAGE_OFFSET 0x000c
  407. #define MEMERR_CPU_LSUESR_ERRWAY_RD(src) (((src) & 0xFF000000) >> 24)
  408. #define MEMERR_CPU_LSUESR_ERRINDEX_RD(src) (((src) & 0x003F0000) >> 16)
  409. #define MEMERR_CPU_LSUESR_ERRINFO_RD(src) (((src) & 0x0000FF00) >> 8)
  410. #define MEMERR_CPU_LSUESR_ERRTYPE_RD(src) (((src) & 0x00000070) >> 4)
  411. #define MEMERR_CPU_LSUESR_MULTCERR_MASK BIT(2)
  412. #define MEMERR_CPU_LSUESR_CERR_MASK BIT(0)
  413. #define MEMERR_CPU_LSUECR_PAGE_OFFSET 0x0008
  414. #define MEMERR_CPU_MMUECR_PAGE_OFFSET 0x0010
  415. #define MEMERR_CPU_MMUESR_PAGE_OFFSET 0x0014
  416. #define MEMERR_CPU_MMUESR_ERRWAY_RD(src) (((src) & 0xFF000000) >> 24)
  417. #define MEMERR_CPU_MMUESR_ERRINDEX_RD(src) (((src) & 0x007F0000) >> 16)
  418. #define MEMERR_CPU_MMUESR_ERRINFO_RD(src) (((src) & 0x0000FF00) >> 8)
  419. #define MEMERR_CPU_MMUESR_ERRREQSTR_LSU_MASK BIT(7)
  420. #define MEMERR_CPU_MMUESR_ERRTYPE_RD(src) (((src) & 0x00000070) >> 4)
  421. #define MEMERR_CPU_MMUESR_MULTCERR_MASK BIT(2)
  422. #define MEMERR_CPU_MMUESR_CERR_MASK BIT(0)
  423. #define MEMERR_CPU_ICFESRA_PAGE_OFFSET 0x0804
  424. #define MEMERR_CPU_LSUESRA_PAGE_OFFSET 0x080c
  425. #define MEMERR_CPU_MMUESRA_PAGE_OFFSET 0x0814
  426. #define MEMERR_L2C_L2ECR_PAGE_OFFSET 0x0000
  427. #define MEMERR_L2C_L2ESR_PAGE_OFFSET 0x0004
  428. #define MEMERR_L2C_L2ESR_ERRSYN_RD(src) (((src) & 0xFF000000) >> 24)
  429. #define MEMERR_L2C_L2ESR_ERRWAY_RD(src) (((src) & 0x00FC0000) >> 18)
  430. #define MEMERR_L2C_L2ESR_ERRCPU_RD(src) (((src) & 0x00020000) >> 17)
  431. #define MEMERR_L2C_L2ESR_ERRGROUP_RD(src) (((src) & 0x0000E000) >> 13)
  432. #define MEMERR_L2C_L2ESR_ERRACTION_RD(src) (((src) & 0x00001C00) >> 10)
  433. #define MEMERR_L2C_L2ESR_ERRTYPE_RD(src) (((src) & 0x00000300) >> 8)
  434. #define MEMERR_L2C_L2ESR_MULTUCERR_MASK BIT(3)
  435. #define MEMERR_L2C_L2ESR_MULTICERR_MASK BIT(2)
  436. #define MEMERR_L2C_L2ESR_UCERR_MASK BIT(1)
  437. #define MEMERR_L2C_L2ESR_ERR_MASK BIT(0)
  438. #define MEMERR_L2C_L2EALR_PAGE_OFFSET 0x0008
  439. #define CPUX_L2C_L2RTOCR_PAGE_OFFSET 0x0010
  440. #define MEMERR_L2C_L2EAHR_PAGE_OFFSET 0x000c
  441. #define CPUX_L2C_L2RTOSR_PAGE_OFFSET 0x0014
  442. #define MEMERR_L2C_L2RTOSR_MULTERR_MASK BIT(1)
  443. #define MEMERR_L2C_L2RTOSR_ERR_MASK BIT(0)
  444. #define CPUX_L2C_L2RTOALR_PAGE_OFFSET 0x0018
  445. #define CPUX_L2C_L2RTOAHR_PAGE_OFFSET 0x001c
  446. #define MEMERR_L2C_L2ESRA_PAGE_OFFSET 0x0804
  447. /*
  448. * Processor Module Domain (PMD) context - Context for a pair of processsors.
  449. * Each PMD consists of 2 CPUs and a shared L2 cache. Each CPU consists of
  450. * its own L1 cache.
  451. */
  452. struct xgene_edac_pmd_ctx {
  453. struct list_head next;
  454. struct device ddev;
  455. char *name;
  456. struct xgene_edac *edac;
  457. struct edac_device_ctl_info *edac_dev;
  458. void __iomem *pmd_csr;
  459. u32 pmd;
  460. int version;
  461. };
  462. static void xgene_edac_pmd_l1_check(struct edac_device_ctl_info *edac_dev,
  463. int cpu_idx)
  464. {
  465. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  466. void __iomem *pg_f;
  467. u32 val;
  468. pg_f = ctx->pmd_csr + cpu_idx * CPU_CSR_STRIDE + CPU_MEMERR_CPU_PAGE;
  469. val = readl(pg_f + MEMERR_CPU_ICFESR_PAGE_OFFSET);
  470. if (val) {
  471. dev_err(edac_dev->dev,
  472. "CPU%d L1 memory error ICF 0x%08X Way 0x%02X Index 0x%02X Info 0x%02X\n",
  473. ctx->pmd * MAX_CPU_PER_PMD + cpu_idx, val,
  474. MEMERR_CPU_ICFESR_ERRWAY_RD(val),
  475. MEMERR_CPU_ICFESR_ERRINDEX_RD(val),
  476. MEMERR_CPU_ICFESR_ERRINFO_RD(val));
  477. if (val & MEMERR_CPU_ICFESR_CERR_MASK)
  478. dev_err(edac_dev->dev,
  479. "One or more correctable error\n");
  480. if (val & MEMERR_CPU_ICFESR_MULTCERR_MASK)
  481. dev_err(edac_dev->dev, "Multiple correctable error\n");
  482. switch (MEMERR_CPU_ICFESR_ERRTYPE_RD(val)) {
  483. case 1:
  484. dev_err(edac_dev->dev, "L1 TLB multiple hit\n");
  485. break;
  486. case 2:
  487. dev_err(edac_dev->dev, "Way select multiple hit\n");
  488. break;
  489. case 3:
  490. dev_err(edac_dev->dev, "Physical tag parity error\n");
  491. break;
  492. case 4:
  493. case 5:
  494. dev_err(edac_dev->dev, "L1 data parity error\n");
  495. break;
  496. case 6:
  497. dev_err(edac_dev->dev, "L1 pre-decode parity error\n");
  498. break;
  499. }
  500. /* Clear any HW errors */
  501. writel(val, pg_f + MEMERR_CPU_ICFESR_PAGE_OFFSET);
  502. if (val & (MEMERR_CPU_ICFESR_CERR_MASK |
  503. MEMERR_CPU_ICFESR_MULTCERR_MASK))
  504. edac_device_handle_ce(edac_dev, 0, 0,
  505. edac_dev->ctl_name);
  506. }
  507. val = readl(pg_f + MEMERR_CPU_LSUESR_PAGE_OFFSET);
  508. if (val) {
  509. dev_err(edac_dev->dev,
  510. "CPU%d memory error LSU 0x%08X Way 0x%02X Index 0x%02X Info 0x%02X\n",
  511. ctx->pmd * MAX_CPU_PER_PMD + cpu_idx, val,
  512. MEMERR_CPU_LSUESR_ERRWAY_RD(val),
  513. MEMERR_CPU_LSUESR_ERRINDEX_RD(val),
  514. MEMERR_CPU_LSUESR_ERRINFO_RD(val));
  515. if (val & MEMERR_CPU_LSUESR_CERR_MASK)
  516. dev_err(edac_dev->dev,
  517. "One or more correctable error\n");
  518. if (val & MEMERR_CPU_LSUESR_MULTCERR_MASK)
  519. dev_err(edac_dev->dev, "Multiple correctable error\n");
  520. switch (MEMERR_CPU_LSUESR_ERRTYPE_RD(val)) {
  521. case 0:
  522. dev_err(edac_dev->dev, "Load tag error\n");
  523. break;
  524. case 1:
  525. dev_err(edac_dev->dev, "Load data error\n");
  526. break;
  527. case 2:
  528. dev_err(edac_dev->dev, "WSL multihit error\n");
  529. break;
  530. case 3:
  531. dev_err(edac_dev->dev, "Store tag error\n");
  532. break;
  533. case 4:
  534. dev_err(edac_dev->dev,
  535. "DTB multihit from load pipeline error\n");
  536. break;
  537. case 5:
  538. dev_err(edac_dev->dev,
  539. "DTB multihit from store pipeline error\n");
  540. break;
  541. }
  542. /* Clear any HW errors */
  543. writel(val, pg_f + MEMERR_CPU_LSUESR_PAGE_OFFSET);
  544. if (val & (MEMERR_CPU_LSUESR_CERR_MASK |
  545. MEMERR_CPU_LSUESR_MULTCERR_MASK))
  546. edac_device_handle_ce(edac_dev, 0, 0,
  547. edac_dev->ctl_name);
  548. }
  549. val = readl(pg_f + MEMERR_CPU_MMUESR_PAGE_OFFSET);
  550. if (val) {
  551. dev_err(edac_dev->dev,
  552. "CPU%d memory error MMU 0x%08X Way 0x%02X Index 0x%02X Info 0x%02X %s\n",
  553. ctx->pmd * MAX_CPU_PER_PMD + cpu_idx, val,
  554. MEMERR_CPU_MMUESR_ERRWAY_RD(val),
  555. MEMERR_CPU_MMUESR_ERRINDEX_RD(val),
  556. MEMERR_CPU_MMUESR_ERRINFO_RD(val),
  557. val & MEMERR_CPU_MMUESR_ERRREQSTR_LSU_MASK ? "LSU" :
  558. "ICF");
  559. if (val & MEMERR_CPU_MMUESR_CERR_MASK)
  560. dev_err(edac_dev->dev,
  561. "One or more correctable error\n");
  562. if (val & MEMERR_CPU_MMUESR_MULTCERR_MASK)
  563. dev_err(edac_dev->dev, "Multiple correctable error\n");
  564. switch (MEMERR_CPU_MMUESR_ERRTYPE_RD(val)) {
  565. case 0:
  566. dev_err(edac_dev->dev, "Stage 1 UTB hit error\n");
  567. break;
  568. case 1:
  569. dev_err(edac_dev->dev, "Stage 1 UTB miss error\n");
  570. break;
  571. case 2:
  572. dev_err(edac_dev->dev, "Stage 1 UTB allocate error\n");
  573. break;
  574. case 3:
  575. dev_err(edac_dev->dev,
  576. "TMO operation single bank error\n");
  577. break;
  578. case 4:
  579. dev_err(edac_dev->dev, "Stage 2 UTB error\n");
  580. break;
  581. case 5:
  582. dev_err(edac_dev->dev, "Stage 2 UTB miss error\n");
  583. break;
  584. case 6:
  585. dev_err(edac_dev->dev, "Stage 2 UTB allocate error\n");
  586. break;
  587. case 7:
  588. dev_err(edac_dev->dev,
  589. "TMO operation multiple bank error\n");
  590. break;
  591. }
  592. /* Clear any HW errors */
  593. writel(val, pg_f + MEMERR_CPU_MMUESR_PAGE_OFFSET);
  594. edac_device_handle_ce(edac_dev, 0, 0, edac_dev->ctl_name);
  595. }
  596. }
  597. static void xgene_edac_pmd_l2_check(struct edac_device_ctl_info *edac_dev)
  598. {
  599. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  600. void __iomem *pg_d;
  601. void __iomem *pg_e;
  602. u32 val_hi;
  603. u32 val_lo;
  604. u32 val;
  605. /* Check L2 */
  606. pg_e = ctx->pmd_csr + CPU_MEMERR_L2C_PAGE;
  607. val = readl(pg_e + MEMERR_L2C_L2ESR_PAGE_OFFSET);
  608. if (val) {
  609. val_lo = readl(pg_e + MEMERR_L2C_L2EALR_PAGE_OFFSET);
  610. val_hi = readl(pg_e + MEMERR_L2C_L2EAHR_PAGE_OFFSET);
  611. dev_err(edac_dev->dev,
  612. "PMD%d memory error L2C L2ESR 0x%08X @ 0x%08X.%08X\n",
  613. ctx->pmd, val, val_hi, val_lo);
  614. dev_err(edac_dev->dev,
  615. "ErrSyndrome 0x%02X ErrWay 0x%02X ErrCpu %d ErrGroup 0x%02X ErrAction 0x%02X\n",
  616. MEMERR_L2C_L2ESR_ERRSYN_RD(val),
  617. MEMERR_L2C_L2ESR_ERRWAY_RD(val),
  618. MEMERR_L2C_L2ESR_ERRCPU_RD(val),
  619. MEMERR_L2C_L2ESR_ERRGROUP_RD(val),
  620. MEMERR_L2C_L2ESR_ERRACTION_RD(val));
  621. if (val & MEMERR_L2C_L2ESR_ERR_MASK)
  622. dev_err(edac_dev->dev,
  623. "One or more correctable error\n");
  624. if (val & MEMERR_L2C_L2ESR_MULTICERR_MASK)
  625. dev_err(edac_dev->dev, "Multiple correctable error\n");
  626. if (val & MEMERR_L2C_L2ESR_UCERR_MASK)
  627. dev_err(edac_dev->dev,
  628. "One or more uncorrectable error\n");
  629. if (val & MEMERR_L2C_L2ESR_MULTUCERR_MASK)
  630. dev_err(edac_dev->dev,
  631. "Multiple uncorrectable error\n");
  632. switch (MEMERR_L2C_L2ESR_ERRTYPE_RD(val)) {
  633. case 0:
  634. dev_err(edac_dev->dev, "Outbound SDB parity error\n");
  635. break;
  636. case 1:
  637. dev_err(edac_dev->dev, "Inbound SDB parity error\n");
  638. break;
  639. case 2:
  640. dev_err(edac_dev->dev, "Tag ECC error\n");
  641. break;
  642. case 3:
  643. dev_err(edac_dev->dev, "Data ECC error\n");
  644. break;
  645. }
  646. /* Clear any HW errors */
  647. writel(val, pg_e + MEMERR_L2C_L2ESR_PAGE_OFFSET);
  648. if (val & (MEMERR_L2C_L2ESR_ERR_MASK |
  649. MEMERR_L2C_L2ESR_MULTICERR_MASK))
  650. edac_device_handle_ce(edac_dev, 0, 0,
  651. edac_dev->ctl_name);
  652. if (val & (MEMERR_L2C_L2ESR_UCERR_MASK |
  653. MEMERR_L2C_L2ESR_MULTUCERR_MASK))
  654. edac_device_handle_ue(edac_dev, 0, 0,
  655. edac_dev->ctl_name);
  656. }
  657. /* Check if any memory request timed out on L2 cache */
  658. pg_d = ctx->pmd_csr + CPU_L2C_PAGE;
  659. val = readl(pg_d + CPUX_L2C_L2RTOSR_PAGE_OFFSET);
  660. if (val) {
  661. val_lo = readl(pg_d + CPUX_L2C_L2RTOALR_PAGE_OFFSET);
  662. val_hi = readl(pg_d + CPUX_L2C_L2RTOAHR_PAGE_OFFSET);
  663. dev_err(edac_dev->dev,
  664. "PMD%d L2C error L2C RTOSR 0x%08X @ 0x%08X.%08X\n",
  665. ctx->pmd, val, val_hi, val_lo);
  666. writel(val, pg_d + CPUX_L2C_L2RTOSR_PAGE_OFFSET);
  667. }
  668. }
  669. static void xgene_edac_pmd_check(struct edac_device_ctl_info *edac_dev)
  670. {
  671. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  672. unsigned int pcp_hp_stat;
  673. int i;
  674. xgene_edac_pcp_rd(ctx->edac, PCPHPERRINTSTS, &pcp_hp_stat);
  675. if (!((PMD0_MERR_MASK << ctx->pmd) & pcp_hp_stat))
  676. return;
  677. /* Check CPU L1 error */
  678. for (i = 0; i < MAX_CPU_PER_PMD; i++)
  679. xgene_edac_pmd_l1_check(edac_dev, i);
  680. /* Check CPU L2 error */
  681. xgene_edac_pmd_l2_check(edac_dev);
  682. }
  683. static void xgene_edac_pmd_cpu_hw_cfg(struct edac_device_ctl_info *edac_dev,
  684. int cpu)
  685. {
  686. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  687. void __iomem *pg_f = ctx->pmd_csr + cpu * CPU_CSR_STRIDE +
  688. CPU_MEMERR_CPU_PAGE;
  689. /*
  690. * Enable CPU memory error:
  691. * MEMERR_CPU_ICFESRA, MEMERR_CPU_LSUESRA, and MEMERR_CPU_MMUESRA
  692. */
  693. writel(0x00000301, pg_f + MEMERR_CPU_ICFECR_PAGE_OFFSET);
  694. writel(0x00000301, pg_f + MEMERR_CPU_LSUECR_PAGE_OFFSET);
  695. writel(0x00000101, pg_f + MEMERR_CPU_MMUECR_PAGE_OFFSET);
  696. }
  697. static void xgene_edac_pmd_hw_cfg(struct edac_device_ctl_info *edac_dev)
  698. {
  699. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  700. void __iomem *pg_d = ctx->pmd_csr + CPU_L2C_PAGE;
  701. void __iomem *pg_e = ctx->pmd_csr + CPU_MEMERR_L2C_PAGE;
  702. /* Enable PMD memory error - MEMERR_L2C_L2ECR and L2C_L2RTOCR */
  703. writel(0x00000703, pg_e + MEMERR_L2C_L2ECR_PAGE_OFFSET);
  704. /* Configure L2C HW request time out feature if supported */
  705. if (ctx->version > 1)
  706. writel(0x00000119, pg_d + CPUX_L2C_L2RTOCR_PAGE_OFFSET);
  707. }
  708. static void xgene_edac_pmd_hw_ctl(struct edac_device_ctl_info *edac_dev,
  709. bool enable)
  710. {
  711. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  712. int i;
  713. /* Enable PMD error interrupt */
  714. if (edac_dev->op_state == OP_RUNNING_INTERRUPT) {
  715. if (enable)
  716. xgene_edac_pcp_clrbits(ctx->edac, PCPHPERRINTMSK,
  717. PMD0_MERR_MASK << ctx->pmd);
  718. else
  719. xgene_edac_pcp_setbits(ctx->edac, PCPHPERRINTMSK,
  720. PMD0_MERR_MASK << ctx->pmd);
  721. }
  722. if (enable) {
  723. xgene_edac_pmd_hw_cfg(edac_dev);
  724. /* Two CPUs per a PMD */
  725. for (i = 0; i < MAX_CPU_PER_PMD; i++)
  726. xgene_edac_pmd_cpu_hw_cfg(edac_dev, i);
  727. }
  728. }
  729. static ssize_t xgene_edac_pmd_l1_inject_ctrl_write(struct file *file,
  730. const char __user *data,
  731. size_t count, loff_t *ppos)
  732. {
  733. struct edac_device_ctl_info *edac_dev = file->private_data;
  734. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  735. void __iomem *cpux_pg_f;
  736. int i;
  737. for (i = 0; i < MAX_CPU_PER_PMD; i++) {
  738. cpux_pg_f = ctx->pmd_csr + i * CPU_CSR_STRIDE +
  739. CPU_MEMERR_CPU_PAGE;
  740. writel(MEMERR_CPU_ICFESR_MULTCERR_MASK |
  741. MEMERR_CPU_ICFESR_CERR_MASK,
  742. cpux_pg_f + MEMERR_CPU_ICFESRA_PAGE_OFFSET);
  743. writel(MEMERR_CPU_LSUESR_MULTCERR_MASK |
  744. MEMERR_CPU_LSUESR_CERR_MASK,
  745. cpux_pg_f + MEMERR_CPU_LSUESRA_PAGE_OFFSET);
  746. writel(MEMERR_CPU_MMUESR_MULTCERR_MASK |
  747. MEMERR_CPU_MMUESR_CERR_MASK,
  748. cpux_pg_f + MEMERR_CPU_MMUESRA_PAGE_OFFSET);
  749. }
  750. return count;
  751. }
  752. static ssize_t xgene_edac_pmd_l2_inject_ctrl_write(struct file *file,
  753. const char __user *data,
  754. size_t count, loff_t *ppos)
  755. {
  756. struct edac_device_ctl_info *edac_dev = file->private_data;
  757. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  758. void __iomem *pg_e = ctx->pmd_csr + CPU_MEMERR_L2C_PAGE;
  759. writel(MEMERR_L2C_L2ESR_MULTUCERR_MASK |
  760. MEMERR_L2C_L2ESR_MULTICERR_MASK |
  761. MEMERR_L2C_L2ESR_UCERR_MASK |
  762. MEMERR_L2C_L2ESR_ERR_MASK,
  763. pg_e + MEMERR_L2C_L2ESRA_PAGE_OFFSET);
  764. return count;
  765. }
  766. static const struct file_operations xgene_edac_pmd_debug_inject_fops[] = {
  767. {
  768. .open = simple_open,
  769. .write = xgene_edac_pmd_l1_inject_ctrl_write,
  770. .llseek = generic_file_llseek, },
  771. {
  772. .open = simple_open,
  773. .write = xgene_edac_pmd_l2_inject_ctrl_write,
  774. .llseek = generic_file_llseek, },
  775. { }
  776. };
  777. static void xgene_edac_pmd_create_debugfs_nodes(
  778. struct edac_device_ctl_info *edac_dev)
  779. {
  780. struct xgene_edac_pmd_ctx *ctx = edac_dev->pvt_info;
  781. struct dentry *edac_debugfs;
  782. char name[30];
  783. if (!IS_ENABLED(CONFIG_EDAC_DEBUG))
  784. return;
  785. /*
  786. * Todo: Switch to common EDAC debug file system for edac device
  787. * when available.
  788. */
  789. if (!ctx->edac->dfs) {
  790. ctx->edac->dfs = debugfs_create_dir(edac_dev->dev->kobj.name,
  791. NULL);
  792. if (!ctx->edac->dfs)
  793. return;
  794. }
  795. sprintf(name, "PMD%d", ctx->pmd);
  796. edac_debugfs = debugfs_create_dir(name, ctx->edac->dfs);
  797. if (!edac_debugfs)
  798. return;
  799. debugfs_create_file("l1_inject_ctrl", S_IWUSR, edac_debugfs, edac_dev,
  800. &xgene_edac_pmd_debug_inject_fops[0]);
  801. debugfs_create_file("l2_inject_ctrl", S_IWUSR, edac_debugfs, edac_dev,
  802. &xgene_edac_pmd_debug_inject_fops[1]);
  803. }
  804. static int xgene_edac_pmd_available(u32 efuse, int pmd)
  805. {
  806. return (efuse & (1 << pmd)) ? 0 : 1;
  807. }
  808. static int xgene_edac_pmd_add(struct xgene_edac *edac, struct device_node *np,
  809. int version)
  810. {
  811. struct edac_device_ctl_info *edac_dev;
  812. struct xgene_edac_pmd_ctx *ctx;
  813. struct resource res;
  814. char edac_name[10];
  815. u32 pmd;
  816. int rc;
  817. u32 val;
  818. if (!devres_open_group(edac->dev, xgene_edac_pmd_add, GFP_KERNEL))
  819. return -ENOMEM;
  820. /* Determine if this PMD is disabled */
  821. if (of_property_read_u32(np, "pmd-controller", &pmd)) {
  822. dev_err(edac->dev, "no pmd-controller property\n");
  823. rc = -ENODEV;
  824. goto err_group;
  825. }
  826. rc = regmap_read(edac->efuse_map, 0, &val);
  827. if (rc)
  828. goto err_group;
  829. if (!xgene_edac_pmd_available(val, pmd)) {
  830. rc = -ENODEV;
  831. goto err_group;
  832. }
  833. sprintf(edac_name, "l2c%d", pmd);
  834. edac_dev = edac_device_alloc_ctl_info(sizeof(*ctx),
  835. edac_name, 1, "l2c", 1, 2, NULL,
  836. 0, edac_device_alloc_index());
  837. if (!edac_dev) {
  838. rc = -ENOMEM;
  839. goto err_group;
  840. }
  841. ctx = edac_dev->pvt_info;
  842. ctx->name = "xgene_pmd_err";
  843. ctx->pmd = pmd;
  844. ctx->edac = edac;
  845. ctx->edac_dev = edac_dev;
  846. ctx->ddev = *edac->dev;
  847. ctx->version = version;
  848. edac_dev->dev = &ctx->ddev;
  849. edac_dev->ctl_name = ctx->name;
  850. edac_dev->dev_name = ctx->name;
  851. edac_dev->mod_name = EDAC_MOD_STR;
  852. rc = of_address_to_resource(np, 0, &res);
  853. if (rc < 0) {
  854. dev_err(edac->dev, "no PMD resource address\n");
  855. goto err_free;
  856. }
  857. ctx->pmd_csr = devm_ioremap_resource(edac->dev, &res);
  858. if (IS_ERR(ctx->pmd_csr)) {
  859. dev_err(edac->dev,
  860. "devm_ioremap_resource failed for PMD resource address\n");
  861. rc = PTR_ERR(ctx->pmd_csr);
  862. goto err_free;
  863. }
  864. if (edac_op_state == EDAC_OPSTATE_POLL)
  865. edac_dev->edac_check = xgene_edac_pmd_check;
  866. xgene_edac_pmd_create_debugfs_nodes(edac_dev);
  867. rc = edac_device_add_device(edac_dev);
  868. if (rc > 0) {
  869. dev_err(edac->dev, "edac_device_add_device failed\n");
  870. rc = -ENOMEM;
  871. goto err_free;
  872. }
  873. if (edac_op_state == EDAC_OPSTATE_INT)
  874. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  875. list_add(&ctx->next, &edac->pmds);
  876. xgene_edac_pmd_hw_ctl(edac_dev, 1);
  877. devres_remove_group(edac->dev, xgene_edac_pmd_add);
  878. dev_info(edac->dev, "X-Gene EDAC PMD%d registered\n", ctx->pmd);
  879. return 0;
  880. err_free:
  881. edac_device_free_ctl_info(edac_dev);
  882. err_group:
  883. devres_release_group(edac->dev, xgene_edac_pmd_add);
  884. return rc;
  885. }
  886. static int xgene_edac_pmd_remove(struct xgene_edac_pmd_ctx *pmd)
  887. {
  888. struct edac_device_ctl_info *edac_dev = pmd->edac_dev;
  889. xgene_edac_pmd_hw_ctl(edac_dev, 0);
  890. edac_device_del_device(edac_dev->dev);
  891. edac_device_free_ctl_info(edac_dev);
  892. return 0;
  893. }
  894. static irqreturn_t xgene_edac_isr(int irq, void *dev_id)
  895. {
  896. struct xgene_edac *ctx = dev_id;
  897. struct xgene_edac_pmd_ctx *pmd;
  898. unsigned int pcp_hp_stat;
  899. unsigned int pcp_lp_stat;
  900. xgene_edac_pcp_rd(ctx, PCPHPERRINTSTS, &pcp_hp_stat);
  901. xgene_edac_pcp_rd(ctx, PCPLPERRINTSTS, &pcp_lp_stat);
  902. if ((MCU_UNCORR_ERR_MASK & pcp_hp_stat) ||
  903. (MCU_CTL_ERR_MASK & pcp_hp_stat) ||
  904. (MCU_CORR_ERR_MASK & pcp_lp_stat)) {
  905. struct xgene_edac_mc_ctx *mcu;
  906. list_for_each_entry(mcu, &ctx->mcus, next) {
  907. xgene_edac_mc_check(mcu->mci);
  908. }
  909. }
  910. list_for_each_entry(pmd, &ctx->pmds, next) {
  911. if ((PMD0_MERR_MASK << pmd->pmd) & pcp_hp_stat)
  912. xgene_edac_pmd_check(pmd->edac_dev);
  913. }
  914. return IRQ_HANDLED;
  915. }
  916. static int xgene_edac_probe(struct platform_device *pdev)
  917. {
  918. struct xgene_edac *edac;
  919. struct device_node *child;
  920. struct resource *res;
  921. int rc;
  922. edac = devm_kzalloc(&pdev->dev, sizeof(*edac), GFP_KERNEL);
  923. if (!edac)
  924. return -ENOMEM;
  925. edac->dev = &pdev->dev;
  926. platform_set_drvdata(pdev, edac);
  927. INIT_LIST_HEAD(&edac->mcus);
  928. INIT_LIST_HEAD(&edac->pmds);
  929. spin_lock_init(&edac->lock);
  930. mutex_init(&edac->mc_lock);
  931. edac->csw_map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
  932. "regmap-csw");
  933. if (IS_ERR(edac->csw_map)) {
  934. dev_err(edac->dev, "unable to get syscon regmap csw\n");
  935. rc = PTR_ERR(edac->csw_map);
  936. goto out_err;
  937. }
  938. edac->mcba_map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
  939. "regmap-mcba");
  940. if (IS_ERR(edac->mcba_map)) {
  941. dev_err(edac->dev, "unable to get syscon regmap mcba\n");
  942. rc = PTR_ERR(edac->mcba_map);
  943. goto out_err;
  944. }
  945. edac->mcbb_map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
  946. "regmap-mcbb");
  947. if (IS_ERR(edac->mcbb_map)) {
  948. dev_err(edac->dev, "unable to get syscon regmap mcbb\n");
  949. rc = PTR_ERR(edac->mcbb_map);
  950. goto out_err;
  951. }
  952. edac->efuse_map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
  953. "regmap-efuse");
  954. if (IS_ERR(edac->efuse_map)) {
  955. dev_err(edac->dev, "unable to get syscon regmap efuse\n");
  956. rc = PTR_ERR(edac->efuse_map);
  957. goto out_err;
  958. }
  959. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  960. edac->pcp_csr = devm_ioremap_resource(&pdev->dev, res);
  961. if (IS_ERR(edac->pcp_csr)) {
  962. dev_err(&pdev->dev, "no PCP resource address\n");
  963. rc = PTR_ERR(edac->pcp_csr);
  964. goto out_err;
  965. }
  966. if (edac_op_state == EDAC_OPSTATE_INT) {
  967. int irq;
  968. int i;
  969. for (i = 0; i < 3; i++) {
  970. irq = platform_get_irq(pdev, i);
  971. if (irq < 0) {
  972. dev_err(&pdev->dev, "No IRQ resource\n");
  973. rc = -EINVAL;
  974. goto out_err;
  975. }
  976. rc = devm_request_irq(&pdev->dev, irq,
  977. xgene_edac_isr, IRQF_SHARED,
  978. dev_name(&pdev->dev), edac);
  979. if (rc) {
  980. dev_err(&pdev->dev,
  981. "Could not request IRQ %d\n", irq);
  982. goto out_err;
  983. }
  984. }
  985. }
  986. for_each_child_of_node(pdev->dev.of_node, child) {
  987. if (!of_device_is_available(child))
  988. continue;
  989. if (of_device_is_compatible(child, "apm,xgene-edac-mc"))
  990. xgene_edac_mc_add(edac, child);
  991. if (of_device_is_compatible(child, "apm,xgene-edac-pmd"))
  992. xgene_edac_pmd_add(edac, child, 1);
  993. if (of_device_is_compatible(child, "apm,xgene-edac-pmd-v2"))
  994. xgene_edac_pmd_add(edac, child, 2);
  995. }
  996. return 0;
  997. out_err:
  998. return rc;
  999. }
  1000. static int xgene_edac_remove(struct platform_device *pdev)
  1001. {
  1002. struct xgene_edac *edac = dev_get_drvdata(&pdev->dev);
  1003. struct xgene_edac_mc_ctx *mcu;
  1004. struct xgene_edac_mc_ctx *temp_mcu;
  1005. struct xgene_edac_pmd_ctx *pmd;
  1006. struct xgene_edac_pmd_ctx *temp_pmd;
  1007. list_for_each_entry_safe(mcu, temp_mcu, &edac->mcus, next) {
  1008. xgene_edac_mc_remove(mcu);
  1009. }
  1010. list_for_each_entry_safe(pmd, temp_pmd, &edac->pmds, next) {
  1011. xgene_edac_pmd_remove(pmd);
  1012. }
  1013. return 0;
  1014. }
  1015. static const struct of_device_id xgene_edac_of_match[] = {
  1016. { .compatible = "apm,xgene-edac" },
  1017. {},
  1018. };
  1019. MODULE_DEVICE_TABLE(of, xgene_edac_of_match);
  1020. static struct platform_driver xgene_edac_driver = {
  1021. .probe = xgene_edac_probe,
  1022. .remove = xgene_edac_remove,
  1023. .driver = {
  1024. .name = "xgene-edac",
  1025. .owner = THIS_MODULE,
  1026. .of_match_table = xgene_edac_of_match,
  1027. },
  1028. };
  1029. static int __init xgene_edac_init(void)
  1030. {
  1031. int rc;
  1032. /* Make sure error reporting method is sane */
  1033. switch (edac_op_state) {
  1034. case EDAC_OPSTATE_POLL:
  1035. case EDAC_OPSTATE_INT:
  1036. break;
  1037. default:
  1038. edac_op_state = EDAC_OPSTATE_INT;
  1039. break;
  1040. }
  1041. rc = platform_driver_register(&xgene_edac_driver);
  1042. if (rc) {
  1043. edac_printk(KERN_ERR, EDAC_MOD_STR,
  1044. "EDAC fails to register\n");
  1045. goto reg_failed;
  1046. }
  1047. return 0;
  1048. reg_failed:
  1049. return rc;
  1050. }
  1051. module_init(xgene_edac_init);
  1052. static void __exit xgene_edac_exit(void)
  1053. {
  1054. platform_driver_unregister(&xgene_edac_driver);
  1055. }
  1056. module_exit(xgene_edac_exit);
  1057. MODULE_LICENSE("GPL");
  1058. MODULE_AUTHOR("Feng Kan <fkan@apm.com>");
  1059. MODULE_DESCRIPTION("APM X-Gene EDAC driver");
  1060. module_param(edac_op_state, int, 0444);
  1061. MODULE_PARM_DESC(edac_op_state,
  1062. "EDAC error reporting state: 0=Poll, 2=Interrupt");