Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 2009 Wind River Systems, |
| 7 | * written by Ralf Baechle <ralf@linux-mips.org> |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 8 | * |
| 9 | * Copyright (c) 2013 by Cisco Systems, Inc. |
| 10 | * All rights reserved. |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/edac.h> |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 17 | #include <linux/ctype.h> |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 18 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 19 | #include <asm/octeon/octeon.h> |
| 20 | #include <asm/octeon/cvmx-lmcx-defs.h> |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 21 | |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 22 | #include "edac_module.h" |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 23 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 24 | #define OCTEON_MAX_MC 4 |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 25 | |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 26 | #define to_mci(k) container_of(k, struct mem_ctl_info, dev) |
| 27 | |
| 28 | struct octeon_lmc_pvt { |
| 29 | unsigned long inject; |
| 30 | unsigned long error_type; |
| 31 | unsigned long dimm; |
| 32 | unsigned long rank; |
| 33 | unsigned long bank; |
| 34 | unsigned long row; |
| 35 | unsigned long col; |
| 36 | }; |
| 37 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 38 | static void octeon_lmc_edac_poll(struct mem_ctl_info *mci) |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 39 | { |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 40 | union cvmx_lmcx_mem_cfg0 cfg0; |
| 41 | bool do_clear = false; |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 42 | char msg[64]; |
| 43 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 44 | cfg0.u64 = cvmx_read_csr(CVMX_LMCX_MEM_CFG0(mci->mc_idx)); |
| 45 | if (cfg0.s.sec_err || cfg0.s.ded_err) { |
| 46 | union cvmx_lmcx_fadr fadr; |
| 47 | fadr.u64 = cvmx_read_csr(CVMX_LMCX_FADR(mci->mc_idx)); |
| 48 | snprintf(msg, sizeof(msg), |
| 49 | "DIMM %d rank %d bank %d row %d col %d", |
| 50 | fadr.cn30xx.fdimm, fadr.cn30xx.fbunk, |
| 51 | fadr.cn30xx.fbank, fadr.cn30xx.frow, fadr.cn30xx.fcol); |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 52 | } |
| 53 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 54 | if (cfg0.s.sec_err) { |
| 55 | edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0, 0, |
| 56 | -1, -1, -1, msg, ""); |
| 57 | cfg0.s.sec_err = -1; /* Done, re-arm */ |
| 58 | do_clear = true; |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 59 | } |
| 60 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 61 | if (cfg0.s.ded_err) { |
| 62 | edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0, |
| 63 | -1, -1, -1, msg, ""); |
| 64 | cfg0.s.ded_err = -1; /* Done, re-arm */ |
| 65 | do_clear = true; |
| 66 | } |
| 67 | if (do_clear) |
| 68 | cvmx_write_csr(CVMX_LMCX_MEM_CFG0(mci->mc_idx), cfg0.u64); |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 69 | } |
| 70 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 71 | static void octeon_lmc_edac_poll_o2(struct mem_ctl_info *mci) |
| 72 | { |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 73 | struct octeon_lmc_pvt *pvt = mci->pvt_info; |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 74 | union cvmx_lmcx_int int_reg; |
| 75 | bool do_clear = false; |
| 76 | char msg[64]; |
| 77 | |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 78 | if (!pvt->inject) |
| 79 | int_reg.u64 = cvmx_read_csr(CVMX_LMCX_INT(mci->mc_idx)); |
| 80 | else { |
| 81 | if (pvt->error_type == 1) |
| 82 | int_reg.s.sec_err = 1; |
| 83 | if (pvt->error_type == 2) |
| 84 | int_reg.s.ded_err = 1; |
| 85 | } |
| 86 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 87 | if (int_reg.s.sec_err || int_reg.s.ded_err) { |
| 88 | union cvmx_lmcx_fadr fadr; |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 89 | if (likely(!pvt->inject)) |
| 90 | fadr.u64 = cvmx_read_csr(CVMX_LMCX_FADR(mci->mc_idx)); |
| 91 | else { |
| 92 | fadr.cn61xx.fdimm = pvt->dimm; |
| 93 | fadr.cn61xx.fbunk = pvt->rank; |
| 94 | fadr.cn61xx.fbank = pvt->bank; |
| 95 | fadr.cn61xx.frow = pvt->row; |
| 96 | fadr.cn61xx.fcol = pvt->col; |
| 97 | } |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 98 | snprintf(msg, sizeof(msg), |
| 99 | "DIMM %d rank %d bank %d row %d col %d", |
| 100 | fadr.cn61xx.fdimm, fadr.cn61xx.fbunk, |
| 101 | fadr.cn61xx.fbank, fadr.cn61xx.frow, fadr.cn61xx.fcol); |
| 102 | } |
| 103 | |
| 104 | if (int_reg.s.sec_err) { |
| 105 | edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0, 0, |
| 106 | -1, -1, -1, msg, ""); |
| 107 | int_reg.s.sec_err = -1; /* Done, re-arm */ |
| 108 | do_clear = true; |
| 109 | } |
| 110 | |
| 111 | if (int_reg.s.ded_err) { |
| 112 | edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0, |
| 113 | -1, -1, -1, msg, ""); |
| 114 | int_reg.s.ded_err = -1; /* Done, re-arm */ |
| 115 | do_clear = true; |
| 116 | } |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 117 | |
| 118 | if (do_clear) { |
| 119 | if (likely(!pvt->inject)) |
| 120 | cvmx_write_csr(CVMX_LMCX_INT(mci->mc_idx), int_reg.u64); |
| 121 | else |
| 122 | pvt->inject = 0; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /************************ MC SYSFS parts ***********************************/ |
| 127 | |
| 128 | /* Only a couple naming differences per template, so very similar */ |
| 129 | #define TEMPLATE_SHOW(reg) \ |
| 130 | static ssize_t octeon_mc_inject_##reg##_show(struct device *dev, \ |
| 131 | struct device_attribute *attr, \ |
| 132 | char *data) \ |
| 133 | { \ |
| 134 | struct mem_ctl_info *mci = to_mci(dev); \ |
| 135 | struct octeon_lmc_pvt *pvt = mci->pvt_info; \ |
| 136 | return sprintf(data, "%016llu\n", (u64)pvt->reg); \ |
| 137 | } |
| 138 | |
| 139 | #define TEMPLATE_STORE(reg) \ |
| 140 | static ssize_t octeon_mc_inject_##reg##_store(struct device *dev, \ |
| 141 | struct device_attribute *attr, \ |
| 142 | const char *data, size_t count) \ |
| 143 | { \ |
| 144 | struct mem_ctl_info *mci = to_mci(dev); \ |
| 145 | struct octeon_lmc_pvt *pvt = mci->pvt_info; \ |
| 146 | if (isdigit(*data)) { \ |
| 147 | if (!kstrtoul(data, 0, &pvt->reg)) \ |
| 148 | return count; \ |
| 149 | } \ |
| 150 | return 0; \ |
| 151 | } |
| 152 | |
| 153 | TEMPLATE_SHOW(inject); |
| 154 | TEMPLATE_STORE(inject); |
| 155 | TEMPLATE_SHOW(dimm); |
| 156 | TEMPLATE_STORE(dimm); |
| 157 | TEMPLATE_SHOW(bank); |
| 158 | TEMPLATE_STORE(bank); |
| 159 | TEMPLATE_SHOW(rank); |
| 160 | TEMPLATE_STORE(rank); |
| 161 | TEMPLATE_SHOW(row); |
| 162 | TEMPLATE_STORE(row); |
| 163 | TEMPLATE_SHOW(col); |
| 164 | TEMPLATE_STORE(col); |
| 165 | |
| 166 | static ssize_t octeon_mc_inject_error_type_store(struct device *dev, |
| 167 | struct device_attribute *attr, |
| 168 | const char *data, |
| 169 | size_t count) |
| 170 | { |
| 171 | struct mem_ctl_info *mci = to_mci(dev); |
| 172 | struct octeon_lmc_pvt *pvt = mci->pvt_info; |
| 173 | |
| 174 | if (!strncmp(data, "single", 6)) |
| 175 | pvt->error_type = 1; |
| 176 | else if (!strncmp(data, "double", 6)) |
| 177 | pvt->error_type = 2; |
| 178 | |
| 179 | return count; |
| 180 | } |
| 181 | |
| 182 | static ssize_t octeon_mc_inject_error_type_show(struct device *dev, |
| 183 | struct device_attribute *attr, |
| 184 | char *data) |
| 185 | { |
| 186 | struct mem_ctl_info *mci = to_mci(dev); |
| 187 | struct octeon_lmc_pvt *pvt = mci->pvt_info; |
| 188 | if (pvt->error_type == 1) |
| 189 | return sprintf(data, "single"); |
| 190 | else if (pvt->error_type == 2) |
| 191 | return sprintf(data, "double"); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static DEVICE_ATTR(inject, S_IRUGO | S_IWUSR, |
| 197 | octeon_mc_inject_inject_show, octeon_mc_inject_inject_store); |
| 198 | static DEVICE_ATTR(error_type, S_IRUGO | S_IWUSR, |
| 199 | octeon_mc_inject_error_type_show, octeon_mc_inject_error_type_store); |
| 200 | static DEVICE_ATTR(dimm, S_IRUGO | S_IWUSR, |
| 201 | octeon_mc_inject_dimm_show, octeon_mc_inject_dimm_store); |
| 202 | static DEVICE_ATTR(rank, S_IRUGO | S_IWUSR, |
| 203 | octeon_mc_inject_rank_show, octeon_mc_inject_rank_store); |
| 204 | static DEVICE_ATTR(bank, S_IRUGO | S_IWUSR, |
| 205 | octeon_mc_inject_bank_show, octeon_mc_inject_bank_store); |
| 206 | static DEVICE_ATTR(row, S_IRUGO | S_IWUSR, |
| 207 | octeon_mc_inject_row_show, octeon_mc_inject_row_store); |
| 208 | static DEVICE_ATTR(col, S_IRUGO | S_IWUSR, |
| 209 | octeon_mc_inject_col_show, octeon_mc_inject_col_store); |
| 210 | |
Takashi Iwai | 1bf06a0 | 2015-02-04 11:48:57 +0100 | [diff] [blame] | 211 | static struct attribute *octeon_dev_attrs[] = { |
| 212 | &dev_attr_inject.attr, |
| 213 | &dev_attr_error_type.attr, |
| 214 | &dev_attr_dimm.attr, |
| 215 | &dev_attr_rank.attr, |
| 216 | &dev_attr_bank.attr, |
| 217 | &dev_attr_row.attr, |
| 218 | &dev_attr_col.attr, |
| 219 | NULL |
| 220 | }; |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 221 | |
Takashi Iwai | 1bf06a0 | 2015-02-04 11:48:57 +0100 | [diff] [blame] | 222 | ATTRIBUTE_GROUPS(octeon_dev); |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 223 | |
Greg Kroah-Hartman | 9b3c6e8 | 2012-12-21 13:23:51 -0800 | [diff] [blame] | 224 | static int octeon_lmc_edac_probe(struct platform_device *pdev) |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 225 | { |
| 226 | struct mem_ctl_info *mci; |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 227 | struct edac_mc_layer layers[1]; |
| 228 | int mc = pdev->id; |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 229 | |
Daniel Walker | 5331de0 | 2013-09-20 15:46:40 -0700 | [diff] [blame] | 230 | opstate_init(); |
| 231 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 232 | layers[0].type = EDAC_MC_LAYER_CHANNEL; |
| 233 | layers[0].size = 1; |
| 234 | layers[0].is_virt_csrow = false; |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 235 | |
Aaro Koskinen | 75a15a7 | 2015-07-01 13:38:52 +0300 | [diff] [blame] | 236 | if (OCTEON_IS_OCTEON1PLUS()) { |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 237 | union cvmx_lmcx_mem_cfg0 cfg0; |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 238 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 239 | cfg0.u64 = cvmx_read_csr(CVMX_LMCX_MEM_CFG0(0)); |
| 240 | if (!cfg0.s.ecc_ena) { |
| 241 | dev_info(&pdev->dev, "Disabled (ECC not enabled)\n"); |
| 242 | return 0; |
| 243 | } |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 244 | |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 245 | mci = edac_mc_alloc(mc, ARRAY_SIZE(layers), layers, sizeof(struct octeon_lmc_pvt)); |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 246 | if (!mci) |
| 247 | return -ENXIO; |
| 248 | |
| 249 | mci->pdev = &pdev->dev; |
| 250 | mci->dev_name = dev_name(&pdev->dev); |
| 251 | |
| 252 | mci->mod_name = "octeon-lmc"; |
| 253 | mci->ctl_name = "octeon-lmc-err"; |
| 254 | mci->edac_check = octeon_lmc_edac_poll; |
| 255 | |
Takashi Iwai | 1bf06a0 | 2015-02-04 11:48:57 +0100 | [diff] [blame] | 256 | if (edac_mc_add_mc_with_groups(mci, octeon_dev_groups)) { |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 257 | dev_err(&pdev->dev, "edac_mc_add_mc() failed\n"); |
| 258 | edac_mc_free(mci); |
| 259 | return -ENXIO; |
| 260 | } |
| 261 | |
| 262 | cfg0.u64 = cvmx_read_csr(CVMX_LMCX_MEM_CFG0(mc)); |
| 263 | cfg0.s.intr_ded_ena = 0; /* We poll */ |
| 264 | cfg0.s.intr_sec_ena = 0; |
| 265 | cvmx_write_csr(CVMX_LMCX_MEM_CFG0(mc), cfg0.u64); |
| 266 | } else { |
| 267 | /* OCTEON II */ |
| 268 | union cvmx_lmcx_int_en en; |
| 269 | union cvmx_lmcx_config config; |
| 270 | |
| 271 | config.u64 = cvmx_read_csr(CVMX_LMCX_CONFIG(0)); |
| 272 | if (!config.s.ecc_ena) { |
| 273 | dev_info(&pdev->dev, "Disabled (ECC not enabled)\n"); |
| 274 | return 0; |
| 275 | } |
| 276 | |
Daniel Walker | 1bc021e | 2013-09-20 15:46:41 -0700 | [diff] [blame] | 277 | mci = edac_mc_alloc(mc, ARRAY_SIZE(layers), layers, sizeof(struct octeon_lmc_pvt)); |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 278 | if (!mci) |
| 279 | return -ENXIO; |
| 280 | |
| 281 | mci->pdev = &pdev->dev; |
| 282 | mci->dev_name = dev_name(&pdev->dev); |
| 283 | |
| 284 | mci->mod_name = "octeon-lmc"; |
| 285 | mci->ctl_name = "co_lmc_err"; |
| 286 | mci->edac_check = octeon_lmc_edac_poll_o2; |
| 287 | |
Takashi Iwai | 1bf06a0 | 2015-02-04 11:48:57 +0100 | [diff] [blame] | 288 | if (edac_mc_add_mc_with_groups(mci, octeon_dev_groups)) { |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 289 | dev_err(&pdev->dev, "edac_mc_add_mc() failed\n"); |
| 290 | edac_mc_free(mci); |
| 291 | return -ENXIO; |
| 292 | } |
| 293 | |
| 294 | en.u64 = cvmx_read_csr(CVMX_LMCX_MEM_CFG0(mc)); |
| 295 | en.s.intr_ded_ena = 0; /* We poll */ |
| 296 | en.s.intr_sec_ena = 0; |
| 297 | cvmx_write_csr(CVMX_LMCX_MEM_CFG0(mc), en.u64); |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 298 | } |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 299 | platform_set_drvdata(pdev, mci); |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 300 | |
| 301 | return 0; |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 302 | } |
| 303 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 304 | static int octeon_lmc_edac_remove(struct platform_device *pdev) |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 305 | { |
| 306 | struct mem_ctl_info *mci = platform_get_drvdata(pdev); |
| 307 | |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 308 | edac_mc_del_mc(&pdev->dev); |
| 309 | edac_mc_free(mci); |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 313 | static struct platform_driver octeon_lmc_edac_driver = { |
| 314 | .probe = octeon_lmc_edac_probe, |
| 315 | .remove = octeon_lmc_edac_remove, |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 316 | .driver = { |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 317 | .name = "octeon_lmc_edac", |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 318 | } |
| 319 | }; |
David Daney | e1ced09 | 2012-11-15 13:58:59 -0800 | [diff] [blame] | 320 | module_platform_driver(octeon_lmc_edac_driver); |
Ralf Baechle | f65aad4 | 2012-10-17 00:39:09 +0200 | [diff] [blame] | 321 | |
| 322 | MODULE_LICENSE("GPL"); |
| 323 | MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>"); |