Channagoud Kadabi | 075db3b | 2017-03-16 14:26:17 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/edac.h> |
| 15 | #include <linux/of_device.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/smp.h> |
| 18 | #include <linux/spinlock.h> |
| 19 | #include <linux/mfd/syscon.h> |
| 20 | #include <linux/regmap.h> |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 22 | #include "edac_core.h" |
| 23 | |
| 24 | #ifdef CONFIG_EDAC_QCOM_LLCC_PANIC_ON_CE |
| 25 | #define LLCC_ERP_PANIC_ON_CE 1 |
| 26 | #else |
| 27 | #define LLCC_ERP_PANIC_ON_CE 0 |
| 28 | #endif |
| 29 | |
| 30 | #ifdef CONFIG_EDAC_QCOM_LLCC_PANIC_ON_UE |
| 31 | #define LLCC_ERP_PANIC_ON_UE 1 |
| 32 | #else |
| 33 | #define LLCC_ERP_PANIC_ON_UE 0 |
| 34 | #endif |
| 35 | |
| 36 | #define EDAC_LLCC "qcom_llcc" |
| 37 | |
| 38 | #define TRP_SYN_REG_CNT 6 |
| 39 | |
| 40 | #define DRP_SYN_REG_CNT 8 |
| 41 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 42 | #define LLCC_COMMON_STATUS0 0x0003000C |
| 43 | #define LLCC_LB_CNT_MASK 0xf0000000 |
| 44 | #define LLCC_LB_CNT_SHIFT 28 |
| 45 | |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 46 | /* single & Double Bit syndrome register offsets */ |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 47 | #define TRP_ECC_SB_ERR_SYN0 0x0002304C |
| 48 | #define TRP_ECC_DB_ERR_SYN0 0x00020370 |
| 49 | #define DRP_ECC_SB_ERR_SYN0 0x0004204C |
| 50 | #define DRP_ECC_DB_ERR_SYN0 0x00042070 |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 51 | |
| 52 | /* Error register offsets */ |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 53 | #define TRP_ECC_ERROR_STATUS1 0x00020348 |
| 54 | #define TRP_ECC_ERROR_STATUS0 0x00020344 |
| 55 | #define DRP_ECC_ERROR_STATUS1 0x00042048 |
| 56 | #define DRP_ECC_ERROR_STATUS0 0x00042044 |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 57 | |
| 58 | /* TRP, DRP interrupt register offsets */ |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 59 | #define DRP_INTERRUPT_STATUS 0x00041000 |
| 60 | #define TRP_INTERRUPT_0_STATUS 0x00020480 |
| 61 | #define DRP_INTERRUPT_CLEAR 0x00041008 |
| 62 | #define DRP_ECC_ERROR_CNTR_CLEAR 0x00040004 |
| 63 | #define TRP_INTERRUPT_0_CLEAR 0x00020484 |
| 64 | #define TRP_ECC_ERROR_CNTR_CLEAR 0x00020440 |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 65 | |
| 66 | /* Mask and shift macros */ |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 67 | #define ECC_DB_ERR_COUNT_MASK 0x0000001f |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 68 | #define ECC_DB_ERR_WAYS_MASK 0xffff0000 |
| 69 | #define ECC_DB_ERR_WAYS_SHIFT 16 |
| 70 | |
| 71 | #define ECC_SB_ERR_COUNT_MASK 0x00ff0000 |
| 72 | #define ECC_SB_ERR_COUNT_SHIFT 16 |
| 73 | #define ECC_SB_ERR_WAYS_MASK 0x0000ffff |
| 74 | |
| 75 | #define SB_ECC_ERROR 0x1 |
| 76 | #define DB_ECC_ERROR 0x2 |
| 77 | |
| 78 | #define DRP_TRP_INT_CLEAR 0x3 |
| 79 | #define DRP_TRP_CNT_CLEAR 0x3 |
| 80 | |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 81 | #ifdef CONFIG_EDAC_LLCC_POLL |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 82 | static int poll_msec = 5000; |
| 83 | module_param(poll_msec, int, 0444); |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 84 | #endif |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 85 | |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 86 | static int interrupt_mode = 1; |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 87 | module_param(interrupt_mode, int, 0444); |
| 88 | MODULE_PARM_DESC(interrupt_mode, |
| 89 | "Controls whether to use interrupt or poll mode"); |
| 90 | |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 91 | enum { |
| 92 | LLCC_DRAM_CE = 0, |
| 93 | LLCC_DRAM_UE, |
| 94 | LLCC_TRAM_CE, |
| 95 | LLCC_TRAM_UE, |
| 96 | }; |
| 97 | |
| 98 | struct errors_edac { |
| 99 | const char *msg; |
| 100 | void (*func)(struct edac_device_ctl_info *edev_ctl, |
| 101 | int inst_nr, int block_nr, const char *msg); |
| 102 | }; |
| 103 | |
| 104 | struct erp_drvdata { |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 105 | struct regmap *llcc_map; |
Channagoud Kadabi | 934571e | 2017-06-05 10:57:25 -0700 | [diff] [blame] | 106 | u32 *llcc_banks; |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 107 | u32 ecc_irq; |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 108 | u32 num_banks; |
| 109 | u32 b_off; |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static const struct errors_edac errors[] = { |
| 113 | {"LLCC Data RAM correctable Error", edac_device_handle_ce}, |
| 114 | {"LLCC Data RAM uncorrectable Error", edac_device_handle_ue}, |
| 115 | {"LLCC Tag RAM correctable Error", edac_device_handle_ce}, |
| 116 | {"LLCC Tag RAM uncorrectable Error", edac_device_handle_ue}, |
| 117 | }; |
| 118 | |
| 119 | /* Clear the error interrupt and counter registers */ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 120 | static void qcom_llcc_clear_errors(int err_type, struct erp_drvdata *drv) |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 121 | { |
| 122 | switch (err_type) { |
| 123 | case LLCC_DRAM_CE: |
| 124 | case LLCC_DRAM_UE: |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 125 | /* Clear the interrupt */ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 126 | regmap_write(drv->llcc_map, drv->b_off + DRP_INTERRUPT_CLEAR, |
| 127 | DRP_TRP_INT_CLEAR); |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 128 | /* Clear the counters */ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 129 | regmap_write(drv->llcc_map, |
| 130 | drv->b_off + DRP_ECC_ERROR_CNTR_CLEAR, |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 131 | DRP_TRP_CNT_CLEAR); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 132 | break; |
| 133 | case LLCC_TRAM_CE: |
| 134 | case LLCC_TRAM_UE: |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 135 | regmap_write(drv->llcc_map, drv->b_off + TRP_INTERRUPT_0_CLEAR, |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 136 | DRP_TRP_INT_CLEAR); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 137 | regmap_write(drv->llcc_map, |
| 138 | drv->b_off + TRP_ECC_ERROR_CNTR_CLEAR, |
| 139 | DRP_TRP_CNT_CLEAR); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* Dump syndrome registers for tag Ram Double bit errors */ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 145 | static void dump_trp_db_syn_reg(struct erp_drvdata *drv, u32 bank) |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 146 | { |
| 147 | int i; |
| 148 | int db_err_cnt; |
| 149 | int db_err_ways; |
| 150 | u32 synd_reg; |
| 151 | u32 synd_val; |
| 152 | |
| 153 | for (i = 0; i < TRP_SYN_REG_CNT; i++) { |
| 154 | synd_reg = TRP_ECC_DB_ERR_SYN0 + (i * 4); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 155 | regmap_read(drv->llcc_map, drv->llcc_banks[bank] + synd_reg, |
| 156 | &synd_val); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 157 | edac_printk(KERN_CRIT, EDAC_LLCC, "TRP_ECC_SYN%d: 0x%8x\n", |
| 158 | i, synd_val); |
| 159 | } |
| 160 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 161 | regmap_read(drv->llcc_map, |
| 162 | drv->llcc_banks[bank] + TRP_ECC_ERROR_STATUS1, &db_err_cnt); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 163 | db_err_cnt = (db_err_cnt & ECC_DB_ERR_COUNT_MASK); |
| 164 | edac_printk(KERN_CRIT, EDAC_LLCC, "Double-Bit error count: 0x%4x\n", |
| 165 | db_err_cnt); |
| 166 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 167 | regmap_read(drv->llcc_map, |
| 168 | drv->llcc_banks[bank] + TRP_ECC_ERROR_STATUS0, &db_err_ways); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 169 | db_err_ways = (db_err_ways & ECC_DB_ERR_WAYS_MASK); |
| 170 | db_err_ways >>= ECC_DB_ERR_WAYS_SHIFT; |
| 171 | |
| 172 | edac_printk(KERN_CRIT, EDAC_LLCC, "Double-Bit error ways: 0x%4x\n", |
| 173 | db_err_ways); |
| 174 | } |
| 175 | |
| 176 | /* Dump syndrome register for tag Ram Single Bit Errors */ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 177 | static void dump_trp_sb_syn_reg(struct erp_drvdata *drv, u32 bank) |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 178 | { |
| 179 | int i; |
| 180 | int sb_err_cnt; |
| 181 | int sb_err_ways; |
| 182 | u32 synd_reg; |
| 183 | u32 synd_val; |
| 184 | |
| 185 | for (i = 0; i < TRP_SYN_REG_CNT; i++) { |
| 186 | synd_reg = TRP_ECC_SB_ERR_SYN0 + (i * 4); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 187 | regmap_read(drv->llcc_map, drv->llcc_banks[bank] + synd_reg, |
| 188 | &synd_val); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 189 | edac_printk(KERN_CRIT, EDAC_LLCC, "TRP_ECC_SYN%d: 0x%8x\n", |
| 190 | i, synd_val); |
| 191 | } |
| 192 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 193 | regmap_read(drv->llcc_map, |
| 194 | drv->llcc_banks[bank] + TRP_ECC_ERROR_STATUS1, &sb_err_cnt); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 195 | sb_err_cnt = (sb_err_cnt & ECC_SB_ERR_COUNT_MASK); |
| 196 | sb_err_cnt >>= ECC_SB_ERR_COUNT_SHIFT; |
| 197 | edac_printk(KERN_CRIT, EDAC_LLCC, "Single-Bit error count: 0x%4x\n", |
| 198 | sb_err_cnt); |
| 199 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 200 | regmap_read(drv->llcc_map, |
| 201 | drv->llcc_banks[bank] + TRP_ECC_ERROR_STATUS0, &sb_err_ways); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 202 | sb_err_ways = sb_err_ways & ECC_SB_ERR_WAYS_MASK; |
| 203 | |
| 204 | edac_printk(KERN_CRIT, EDAC_LLCC, "Single-Bit error ways: 0x%4x\n", |
| 205 | sb_err_ways); |
| 206 | } |
| 207 | |
| 208 | /* Dump syndrome registers for Data Ram Double bit errors */ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 209 | static void dump_drp_db_syn_reg(struct erp_drvdata *drv, u32 bank) |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 210 | { |
| 211 | int i; |
| 212 | int db_err_cnt; |
| 213 | int db_err_ways; |
| 214 | u32 synd_reg; |
| 215 | u32 synd_val; |
| 216 | |
| 217 | for (i = 0; i < DRP_SYN_REG_CNT; i++) { |
| 218 | synd_reg = DRP_ECC_DB_ERR_SYN0 + (i * 4); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 219 | regmap_read(drv->llcc_map, drv->llcc_banks[bank] + synd_reg, |
| 220 | &synd_val); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 221 | edac_printk(KERN_CRIT, EDAC_LLCC, "DRP_ECC_SYN%d: 0x%8x\n", |
| 222 | i, synd_val); |
| 223 | } |
| 224 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 225 | regmap_read(drv->llcc_map, |
| 226 | drv->llcc_banks[bank] + DRP_ECC_ERROR_STATUS1, &db_err_cnt); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 227 | db_err_cnt = (db_err_cnt & ECC_DB_ERR_COUNT_MASK); |
| 228 | edac_printk(KERN_CRIT, EDAC_LLCC, "Double-Bit error count: 0x%4x\n", |
| 229 | db_err_cnt); |
| 230 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 231 | regmap_read(drv->llcc_map, |
| 232 | drv->llcc_banks[bank] + DRP_ECC_ERROR_STATUS0, &db_err_ways); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 233 | db_err_ways &= ECC_DB_ERR_WAYS_MASK; |
| 234 | db_err_ways >>= ECC_DB_ERR_WAYS_SHIFT; |
| 235 | edac_printk(KERN_CRIT, EDAC_LLCC, "Double-Bit error ways: 0x%4x\n", |
| 236 | db_err_ways); |
| 237 | } |
| 238 | |
| 239 | /* Dump Syndrome registers for Data Ram Single bit errors*/ |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 240 | static void dump_drp_sb_syn_reg(struct erp_drvdata *drv, u32 bank) |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 241 | { |
| 242 | int i; |
| 243 | int sb_err_cnt; |
| 244 | int sb_err_ways; |
| 245 | u32 synd_reg; |
| 246 | u32 synd_val; |
| 247 | |
| 248 | for (i = 0; i < DRP_SYN_REG_CNT; i++) { |
Channagoud Kadabi | 075db3b | 2017-03-16 14:26:17 -0700 | [diff] [blame] | 249 | synd_reg = DRP_ECC_SB_ERR_SYN0 + (i * 4); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 250 | regmap_read(drv->llcc_map, drv->llcc_banks[bank] + synd_reg, |
| 251 | &synd_val); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 252 | edac_printk(KERN_CRIT, EDAC_LLCC, "DRP_ECC_SYN%d: 0x%8x\n", |
| 253 | i, synd_val); |
| 254 | } |
| 255 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 256 | regmap_read(drv->llcc_map, |
| 257 | drv->llcc_banks[bank] + DRP_ECC_ERROR_STATUS1, &sb_err_cnt); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 258 | sb_err_cnt &= ECC_SB_ERR_COUNT_MASK; |
| 259 | sb_err_cnt >>= ECC_SB_ERR_COUNT_SHIFT; |
| 260 | edac_printk(KERN_CRIT, EDAC_LLCC, "Single-Bit error count: 0x%4x\n", |
| 261 | sb_err_cnt); |
| 262 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 263 | regmap_read(drv->llcc_map, |
| 264 | drv->llcc_banks[bank] + DRP_ECC_ERROR_STATUS0, &sb_err_ways); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 265 | sb_err_ways = sb_err_ways & ECC_SB_ERR_WAYS_MASK; |
| 266 | |
| 267 | edac_printk(KERN_CRIT, EDAC_LLCC, "Single-Bit error ways: 0x%4x\n", |
| 268 | sb_err_ways); |
| 269 | } |
| 270 | |
| 271 | |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 272 | static void dump_syn_reg(struct edac_device_ctl_info *edev_ctl, |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 273 | int err_type, u32 bank) |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 274 | { |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 275 | struct erp_drvdata *drv = edev_ctl->pvt_info; |
| 276 | |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 277 | switch (err_type) { |
| 278 | case LLCC_DRAM_CE: |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 279 | dump_drp_sb_syn_reg(drv, bank); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 280 | break; |
| 281 | case LLCC_DRAM_UE: |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 282 | dump_drp_db_syn_reg(drv, bank); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 283 | break; |
| 284 | case LLCC_TRAM_CE: |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 285 | dump_trp_sb_syn_reg(drv, bank); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 286 | break; |
| 287 | case LLCC_TRAM_UE: |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 288 | dump_trp_db_syn_reg(drv, bank); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 289 | break; |
| 290 | } |
| 291 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 292 | qcom_llcc_clear_errors(err_type, drv); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 293 | |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 294 | errors[err_type].func(edev_ctl, 0, bank, errors[err_type].msg); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 297 | static void qcom_llcc_check_cache_errors |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 298 | (struct edac_device_ctl_info *edev_ctl) |
| 299 | { |
| 300 | u32 drp_error; |
| 301 | u32 trp_error; |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 302 | struct erp_drvdata *drv = edev_ctl->pvt_info; |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 303 | u32 i; |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 304 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 305 | for (i = 0; i < drv->num_banks; i++) { |
| 306 | /* Look for Data RAM errors */ |
| 307 | regmap_read(drv->llcc_map, |
| 308 | drv->llcc_banks[i] + DRP_INTERRUPT_STATUS, &drp_error); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 309 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 310 | if (drp_error & SB_ECC_ERROR) { |
| 311 | edac_printk(KERN_CRIT, EDAC_LLCC, |
| 312 | "Single Bit Error detected in Data Ram\n"); |
| 313 | dump_syn_reg(edev_ctl, LLCC_DRAM_CE, i); |
| 314 | } else if (drp_error & DB_ECC_ERROR) { |
| 315 | edac_printk(KERN_CRIT, EDAC_LLCC, |
| 316 | "Double Bit Error detected in Data Ram\n"); |
| 317 | dump_syn_reg(edev_ctl, LLCC_DRAM_UE, i); |
| 318 | } |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 319 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 320 | /* Look for Tag RAM errors */ |
| 321 | regmap_read(drv->llcc_map, |
| 322 | drv->llcc_banks[i] + TRP_INTERRUPT_0_STATUS, |
| 323 | &trp_error); |
| 324 | if (trp_error & SB_ECC_ERROR) { |
| 325 | edac_printk(KERN_CRIT, EDAC_LLCC, |
| 326 | "Single Bit Error detected in Tag Ram\n"); |
| 327 | dump_syn_reg(edev_ctl, LLCC_TRAM_CE, i); |
| 328 | } else if (trp_error & DB_ECC_ERROR) { |
| 329 | edac_printk(KERN_CRIT, EDAC_LLCC, |
| 330 | "Double Bit Error detected in Tag Ram\n"); |
| 331 | dump_syn_reg(edev_ctl, LLCC_TRAM_UE, i); |
| 332 | } |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 336 | #ifdef CONFIG_EDAC_LLCC_POLL |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 337 | static void qcom_llcc_poll_cache_errors(struct edac_device_ctl_info *edev_ctl) |
| 338 | { |
| 339 | qcom_llcc_check_cache_errors(edev_ctl); |
| 340 | } |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 341 | #endif |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 342 | |
| 343 | static irqreturn_t llcc_ecc_irq_handler |
| 344 | (int irq, void *edev_ctl) |
| 345 | { |
| 346 | qcom_llcc_check_cache_errors(edev_ctl); |
| 347 | return IRQ_HANDLED; |
| 348 | } |
| 349 | |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 350 | static int qcom_llcc_erp_probe(struct platform_device *pdev) |
| 351 | { |
| 352 | int rc = 0; |
| 353 | struct erp_drvdata *drv; |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 354 | struct edac_device_ctl_info *edev_ctl; |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 355 | struct device *dev = &pdev->dev; |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 356 | u32 num_banks; |
| 357 | struct regmap *llcc_map = NULL; |
| 358 | |
| 359 | llcc_map = syscon_node_to_regmap(dev->parent->of_node); |
| 360 | if (IS_ERR(llcc_map)) { |
| 361 | dev_err(dev, "no regmap for syscon llcc parent\n"); |
| 362 | return -ENOMEM; |
| 363 | } |
| 364 | |
| 365 | /* Find the number of LLC banks supported */ |
| 366 | regmap_read(llcc_map, LLCC_COMMON_STATUS0, |
| 367 | &num_banks); |
| 368 | |
| 369 | num_banks &= LLCC_LB_CNT_MASK; |
| 370 | num_banks >>= LLCC_LB_CNT_SHIFT; |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 371 | |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 372 | /* Allocate edac control info */ |
| 373 | edev_ctl = edac_device_alloc_ctl_info(sizeof(*drv), "qcom-llcc", 1, |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 374 | "bank", num_banks, 1, NULL, 0, |
| 375 | edac_device_alloc_index()); |
Channagoud Kadabi | 934571e | 2017-06-05 10:57:25 -0700 | [diff] [blame] | 376 | |
| 377 | if (!edev_ctl) |
| 378 | return -ENOMEM; |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 379 | |
| 380 | edev_ctl->dev = dev; |
| 381 | edev_ctl->mod_name = dev_name(dev); |
| 382 | edev_ctl->dev_name = dev_name(dev); |
| 383 | edev_ctl->ctl_name = "llcc"; |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 384 | #ifdef CONFIG_EDAC_LLCC_POLL |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 385 | edev_ctl->poll_msec = poll_msec; |
| 386 | edev_ctl->edac_check = qcom_llcc_poll_cache_errors; |
| 387 | edev_ctl->defer_work = 1; |
Channagoud Kadabi | 13d9d33 | 2017-04-14 20:41:15 -0700 | [diff] [blame] | 388 | #endif |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 389 | edev_ctl->panic_on_ce = LLCC_ERP_PANIC_ON_CE; |
| 390 | edev_ctl->panic_on_ue = LLCC_ERP_PANIC_ON_UE; |
| 391 | |
| 392 | drv = edev_ctl->pvt_info; |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 393 | drv->num_banks = num_banks; |
| 394 | drv->llcc_map = llcc_map; |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 395 | |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 396 | rc = edac_device_add_device(edev_ctl); |
| 397 | if (rc) |
| 398 | goto out_mem; |
Channagoud Kadabi | c26a891 | 2016-11-21 13:57:20 -0800 | [diff] [blame] | 399 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 400 | drv->llcc_banks = devm_kzalloc(&pdev->dev, |
Channagoud Kadabi | 934571e | 2017-06-05 10:57:25 -0700 | [diff] [blame] | 401 | sizeof(u32) * drv->num_banks, GFP_KERNEL); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 402 | |
Channagoud Kadabi | 934571e | 2017-06-05 10:57:25 -0700 | [diff] [blame] | 403 | if (!drv->llcc_banks) { |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 404 | dev_err(dev, "Cannot allocate memory for llcc_banks\n"); |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 405 | rc = -ENOMEM; |
| 406 | goto out_dev; |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 409 | rc = of_property_read_u32_array(dev->parent->of_node, |
Channagoud Kadabi | 934571e | 2017-06-05 10:57:25 -0700 | [diff] [blame] | 410 | "qcom,llcc-banks-off", drv->llcc_banks, drv->num_banks); |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 411 | if (rc) { |
| 412 | dev_err(dev, "Cannot read llcc-banks-off property\n"); |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 413 | goto out_dev; |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | rc = of_property_read_u32(dev->parent->of_node, |
| 417 | "qcom,llcc-broadcast-off", &drv->b_off); |
| 418 | if (rc) { |
| 419 | dev_err(dev, "Cannot read llcc-broadcast-off property\n"); |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 420 | goto out_dev; |
Channagoud Kadabi | c0a72e7 | 2017-03-27 21:57:09 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 423 | platform_set_drvdata(pdev, edev_ctl); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 424 | |
Channagoud Kadabi | 31a5879 | 2017-08-31 16:34:05 -0700 | [diff] [blame] | 425 | if (interrupt_mode) { |
| 426 | drv->ecc_irq = platform_get_irq_byname(pdev, "ecc_irq"); |
| 427 | if (!drv->ecc_irq) { |
| 428 | rc = -ENODEV; |
| 429 | goto out_dev; |
| 430 | } |
| 431 | |
| 432 | rc = devm_request_irq(dev, drv->ecc_irq, llcc_ecc_irq_handler, |
| 433 | IRQF_TRIGGER_HIGH, "llcc_ecc", edev_ctl); |
| 434 | if (rc) { |
| 435 | dev_err(dev, "failed to request ecc irq\n"); |
| 436 | goto out_dev; |
| 437 | } |
| 438 | } |
| 439 | |
Channagoud Kadabi | 7814439 | 2017-08-09 13:25:52 -0700 | [diff] [blame] | 440 | return 0; |
| 441 | |
| 442 | out_dev: |
| 443 | edac_device_del_device(edev_ctl->dev); |
| 444 | out_mem: |
| 445 | edac_device_free_ctl_info(edev_ctl); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 446 | |
| 447 | return rc; |
| 448 | } |
| 449 | |
| 450 | static int qcom_llcc_erp_remove(struct platform_device *pdev) |
| 451 | { |
Channagoud Kadabi | 5c9de9a | 2016-10-03 23:03:07 -0700 | [diff] [blame] | 452 | struct edac_device_ctl_info *edev_ctl = dev_get_drvdata(&pdev->dev); |
Channagoud Kadabi | 845ae7c | 2016-06-23 18:55:38 -0700 | [diff] [blame] | 453 | |
| 454 | edac_device_del_device(edev_ctl->dev); |
| 455 | edac_device_free_ctl_info(edev_ctl); |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static const struct of_device_id qcom_llcc_erp_match_table[] = { |
| 461 | { .compatible = "qcom,llcc-erp" }, |
| 462 | { }, |
| 463 | }; |
| 464 | |
| 465 | static struct platform_driver qcom_llcc_erp_driver = { |
| 466 | .probe = qcom_llcc_erp_probe, |
| 467 | .remove = qcom_llcc_erp_remove, |
| 468 | .driver = { |
| 469 | .name = "qcom_llcc_erp", |
| 470 | .owner = THIS_MODULE, |
| 471 | .of_match_table = qcom_llcc_erp_match_table, |
| 472 | }, |
| 473 | }; |
| 474 | |
| 475 | static int __init qcom_llcc_erp_init(void) |
| 476 | { |
| 477 | return platform_driver_register(&qcom_llcc_erp_driver); |
| 478 | } |
| 479 | module_init(qcom_llcc_erp_init); |
| 480 | |
| 481 | static void __exit qcom_llcc_erp_exit(void) |
| 482 | { |
| 483 | platform_driver_unregister(&qcom_llcc_erp_driver); |
| 484 | } |
| 485 | module_exit(qcom_llcc_erp_exit); |
| 486 | |
| 487 | MODULE_DESCRIPTION("QCOM LLCC Error Reporting"); |
| 488 | MODULE_LICENSE("GPL v2"); |