xgene_edac.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  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. .of_match_table = xgene_edac_of_match,
  1026. },
  1027. };
  1028. static int __init xgene_edac_init(void)
  1029. {
  1030. int rc;
  1031. /* Make sure error reporting method is sane */
  1032. switch (edac_op_state) {
  1033. case EDAC_OPSTATE_POLL:
  1034. case EDAC_OPSTATE_INT:
  1035. break;
  1036. default:
  1037. edac_op_state = EDAC_OPSTATE_INT;
  1038. break;
  1039. }
  1040. rc = platform_driver_register(&xgene_edac_driver);
  1041. if (rc) {
  1042. edac_printk(KERN_ERR, EDAC_MOD_STR,
  1043. "EDAC fails to register\n");
  1044. goto reg_failed;
  1045. }
  1046. return 0;
  1047. reg_failed:
  1048. return rc;
  1049. }
  1050. module_init(xgene_edac_init);
  1051. static void __exit xgene_edac_exit(void)
  1052. {
  1053. platform_driver_unregister(&xgene_edac_driver);
  1054. }
  1055. module_exit(xgene_edac_exit);
  1056. MODULE_LICENSE("GPL");
  1057. MODULE_AUTHOR("Feng Kan <fkan@apm.com>");
  1058. MODULE_DESCRIPTION("APM X-Gene EDAC driver");
  1059. module_param(edac_op_state, int, 0444);
  1060. MODULE_PARM_DESC(edac_op_state,
  1061. "EDAC error reporting state: 0=Poll, 2=Interrupt");