12 #include <linux/module.h>
15 #include <linux/ctype.h>
28 static int edac_dev_idx;
30 static int edac_pci_idx;
32 static int edac_mc_idx;
34 static u32 orig_ddr_err_disable;
35 static u32 orig_ddr_err_sbe;
41 static u32 orig_pci_err_cap_dr;
42 static u32 orig_pci_err_en;
45 static u32 orig_l2_err_disable;
46 #ifdef CONFIG_FSL_SOC_BOOKE
47 static u32 orig_hid1[2];
52 #define to_mci(k) container_of(k, struct mem_ctl_info, dev)
76 static ssize_t mpc85xx_mc_inject_ctrl_show(
struct device *dev,
86 static ssize_t mpc85xx_mc_inject_data_hi_store(
struct device *dev,
88 const char *data,
size_t count)
100 static ssize_t mpc85xx_mc_inject_data_lo_store(
struct device *dev,
102 const char *data,
size_t count)
114 static ssize_t mpc85xx_mc_inject_ctrl_store(
struct device *dev,
116 const char *data,
size_t count)
129 mpc85xx_mc_inject_data_hi_show, mpc85xx_mc_inject_data_hi_store);
131 mpc85xx_mc_inject_data_lo_show, mpc85xx_mc_inject_data_lo_store);
133 mpc85xx_mc_inject_ctrl_show, mpc85xx_mc_inject_ctrl_store);
135 static int mpc85xx_create_sysfs_attributes(
struct mem_ctl_info *mci)
152 static void mpc85xx_remove_sysfs_attributes(
struct mem_ctl_info *mci)
162 static void mpc85xx_pci_check(
struct edac_pci_ctl_info *pci)
201 struct edac_pci_ctl_info *pci =
dev_id;
210 mpc85xx_pci_check(pci);
217 struct edac_pci_ctl_info *pci;
239 pdata = pci->pvt_info;
240 pdata->
name =
"mpc85xx_pci_err";
245 pci->ctl_name = pdata->
name;
246 pci->dev_name = dev_name(&op->
dev);
249 pci->edac_check = mpc85xx_pci_check;
256 "PCI err regs\n", __func__);
278 orig_pci_err_cap_dr =
293 edac_dbg(3,
"failed edac_pci_add_device()\n");
299 res = devm_request_irq(&op->
dev, pdata->
irq,
301 "[EDAC] PCI err", pci);
304 "%s: Unable to requiest irq %d for "
305 "MPC85xx PCI err\n", __func__, pdata->
irq);
338 orig_pci_err_cap_dr);
359 *edac_dev,
char *data)
367 *edac_dev,
char *data)
375 *edac_dev,
char *data)
383 *edac_dev,
const char *data,
396 *edac_dev,
const char *data,
409 *edac_dev,
const char *data,
424 .name =
"inject_data_hi",
427 .
show = mpc85xx_l2_inject_data_hi_show,
428 .
store = mpc85xx_l2_inject_data_hi_store},
431 .name =
"inject_data_lo",
434 .
show = mpc85xx_l2_inject_data_lo_show,
435 .
store = mpc85xx_l2_inject_data_lo_store},
438 .name =
"inject_ctrl",
441 .
show = mpc85xx_l2_inject_ctrl_show,
442 .
store = mpc85xx_l2_inject_ctrl_store},
446 .attr = {.name =
NULL}
469 printk(
KERN_ERR "L2 Error Detect Register: 0x%08x\n", err_detect);
491 static irqreturn_t mpc85xx_l2_isr(
int irq,
void *dev_id)
499 if (!(err_detect & L2_EDE_MASK))
502 mpc85xx_l2_check(edac_dev);
518 "cpu", 1,
"L", 1, 2,
NULL, 0,
526 pdata->
name =
"mpc85xx_l2_err";
536 "L2 err regs\n", __func__);
570 mpc85xx_set_l2_sysfs_attributes(edac_dev);
575 edac_dbg(3,
"failed edac_device_add_device()\n");
581 res = devm_request_irq(&op->
dev, pdata->
irq,
583 "[EDAC] L2 err", edac_dev);
586 "%s: Unable to requiest irq %d for "
587 "MPC85xx L2 err\n", __func__, pdata->
irq);
634 static struct of_device_id mpc85xx_l2_err_of_match[] = {
636 { .compatible =
"fsl,8540-l2-cache-controller", },
637 { .compatible =
"fsl,8541-l2-cache-controller", },
638 { .compatible =
"fsl,8544-l2-cache-controller", },
639 { .compatible =
"fsl,8548-l2-cache-controller", },
640 { .compatible =
"fsl,8555-l2-cache-controller", },
641 { .compatible =
"fsl,8568-l2-cache-controller", },
642 { .compatible =
"fsl,mpc8536-l2-cache-controller", },
643 { .compatible =
"fsl,mpc8540-l2-cache-controller", },
644 { .compatible =
"fsl,mpc8541-l2-cache-controller", },
645 { .compatible =
"fsl,mpc8544-l2-cache-controller", },
646 { .compatible =
"fsl,mpc8548-l2-cache-controller", },
647 { .compatible =
"fsl,mpc8555-l2-cache-controller", },
648 { .compatible =
"fsl,mpc8560-l2-cache-controller", },
649 { .compatible =
"fsl,mpc8568-l2-cache-controller", },
650 { .compatible =
"fsl,mpc8569-l2-cache-controller", },
651 { .compatible =
"fsl,mpc8572-l2-cache-controller", },
652 { .compatible =
"fsl,p1020-l2-cache-controller", },
653 { .compatible =
"fsl,p1021-l2-cache-controller", },
654 { .compatible =
"fsl,p2020-l2-cache-controller", },
660 .probe = mpc85xx_l2_err_probe,
661 .remove = mpc85xx_l2_err_remove,
663 .name =
"mpc85xx_l2_err",
665 .of_match_table = mpc85xx_l2_err_of_match,
677 static unsigned int ecc_table[16] = {
680 0xf00fe11e, 0xc33c0ff7,
681 0x00ff00ff, 0x00fff0ff,
682 0x0f0f0f0f, 0x0f0fff00,
683 0x11113333, 0x7777000f,
684 0x22224444, 0x8888222f,
685 0x44448888, 0xffff4441,
686 0x8888ffff, 0x11118882,
687 0xffff1111, 0x22221114,
702 for (i = 0; i < 8; i++) {
703 mask_high = ecc_table[i * 2];
704 mask_low = ecc_table[i * 2 + 1];
707 for (j = 0; j < 32; j++) {
708 if ((mask_high >> j) & 1)
709 bit_cnt ^= (high >>
j) & 1;
710 if ((mask_low >> j) & 1)
711 bit_cnt ^= (low >> j) & 1;
725 static u8 syndrome_from_bit(
unsigned int bit) {
734 for (i = bit < 32; i < 16; i += 2)
735 syndrome |= ((ecc_table[i] >> (bit % 32)) & 1) << (i / 2);
744 static void sbe_ecc_decode(
u32 cap_high,
u32 cap_low,
u32 cap_ecc,
745 int *bad_data_bit,
int *bad_ecc_bit)
757 syndrome = calculate_ecc(cap_high, cap_low) ^ cap_ecc;
760 for (i = 0; i < 64; i++) {
761 if (syndrome == syndrome_from_bit(i)) {
768 for (i = 0; i < 8; i++) {
769 if ((syndrome >> i) & 0x1) {
817 for (row_index = 0; row_index < mci->
nr_csrows; row_index++) {
818 csrow = mci->
csrows[row_index];
830 if ((err_detect &
DDR_EDE_SBE) && (bus_width == 64)) {
831 sbe_ecc_decode(cap_high, cap_low, syndrome,
832 &bad_data_bit, &bad_ecc_bit);
834 if (bad_data_bit != -1)
836 "Faulty Data bit: %d\n", bad_data_bit);
837 if (bad_ecc_bit != -1)
839 "Faulty ECC bit: %d\n", bad_ecc_bit);
842 "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
843 cap_high ^ (1 << (bad_data_bit - 32)),
844 cap_low ^ (1 << bad_data_bit),
845 syndrome ^ (1 << bad_ecc_bit));
849 "Captured Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
850 cap_high, cap_low, syndrome);
858 if (err_detect & DDR_EDE_SBE)
873 static irqreturn_t mpc85xx_mc_isr(
int irq,
void *dev_id)
883 mpc85xx_mc_check(mci);
934 for (index = 0; index < mci->
nr_csrows; index++) {
944 start = (cs_bnds & 0xffff0000) >> 16;
945 end = (cs_bnds & 0x0000ffff);
981 layers[0].is_virt_csrow =
true;
984 layers[1].is_virt_csrow =
false;
993 pdata->
name =
"mpc85xx_mc_err";
1046 mpc85xx_init_csrows(mci);
1049 orig_ddr_err_disable =
1057 edac_dbg(3,
"failed edac_mc_add_mc()\n");
1061 if (mpc85xx_create_sysfs_attributes(mci)) {
1063 edac_dbg(3,
"failed edac_mc_add_mc()\n");
1080 res = devm_request_irq(&op->
dev, pdata->
irq,
1083 "[EDAC] MC err", mci);
1086 "MPC85xx DRAM ERR\n", __func__, pdata->
irq);
1123 orig_ddr_err_disable);
1126 mpc85xx_remove_sysfs_attributes(mci);
1132 static struct of_device_id mpc85xx_mc_err_of_match[] = {
1134 { .compatible =
"fsl,8540-memory-controller", },
1135 { .compatible =
"fsl,8541-memory-controller", },
1136 { .compatible =
"fsl,8544-memory-controller", },
1137 { .compatible =
"fsl,8548-memory-controller", },
1138 { .compatible =
"fsl,8555-memory-controller", },
1139 { .compatible =
"fsl,8568-memory-controller", },
1140 { .compatible =
"fsl,mpc8536-memory-controller", },
1141 { .compatible =
"fsl,mpc8540-memory-controller", },
1142 { .compatible =
"fsl,mpc8541-memory-controller", },
1143 { .compatible =
"fsl,mpc8544-memory-controller", },
1144 { .compatible =
"fsl,mpc8548-memory-controller", },
1145 { .compatible =
"fsl,mpc8555-memory-controller", },
1146 { .compatible =
"fsl,mpc8560-memory-controller", },
1147 { .compatible =
"fsl,mpc8568-memory-controller", },
1148 { .compatible =
"fsl,mpc8569-memory-controller", },
1149 { .compatible =
"fsl,mpc8572-memory-controller", },
1150 { .compatible =
"fsl,mpc8349-memory-controller", },
1151 { .compatible =
"fsl,p1020-memory-controller", },
1152 { .compatible =
"fsl,p1021-memory-controller", },
1153 { .compatible =
"fsl,p2020-memory-controller", },
1154 { .compatible =
"fsl,qoriq-memory-controller", },
1160 .probe = mpc85xx_mc_err_probe,
1161 .remove = mpc85xx_mc_err_remove,
1163 .name =
"mpc85xx_mc_err",
1165 .of_match_table = mpc85xx_mc_err_of_match,
1169 #ifdef CONFIG_FSL_SOC_BOOKE
1170 static void __init mpc85xx_mc_clear_rfxe(
void *data)
1177 static int __init mpc85xx_mc_init(
void)
1183 "(C) 2006 Montavista Software\n");
1203 #ifdef CONFIG_FSL_SOC_BOOKE
1206 if ((
PVR_VER(pvr) == PVR_VER_E500V1) ||
1207 (
PVR_VER(pvr) == PVR_VER_E500V2)) {
1222 #ifdef CONFIG_FSL_SOC_BOOKE
1223 static void __exit mpc85xx_mc_restore_hid1(
void *data)
1229 static void __exit mpc85xx_mc_exit(
void)
1231 #ifdef CONFIG_FSL_SOC_BOOKE
1234 if ((
PVR_VER(pvr) == PVR_VER_E500V1) ||
1235 (
PVR_VER(pvr) == PVR_VER_E500V2)) {
1249 "EDAC Error Reporting state: 0=Poll, 2=Interrupt");