Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Nuovation System Designs, LLC |
| 3 | * Grant Erickson <gerickson@nuovations.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; version 2 of the |
| 8 | * License. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #include <linux/edac.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/of_device.h> |
| 19 | #include <linux/of_platform.h> |
| 20 | #include <linux/types.h> |
| 21 | |
| 22 | #include <asm/dcr.h> |
| 23 | |
| 24 | #include "edac_core.h" |
| 25 | #include "ppc4xx_edac.h" |
| 26 | |
| 27 | /* |
| 28 | * This file implements a driver for monitoring and handling events |
| 29 | * associated with the IMB DDR2 ECC controller found in the AMCC/IBM |
| 30 | * 405EX[r], 440SP, 440SPe, 460EX, 460GT and 460SX. |
| 31 | * |
| 32 | * As realized in the 405EX[r], this controller features: |
| 33 | * |
| 34 | * - Support for registered- and non-registered DDR1 and DDR2 memory. |
| 35 | * - 32-bit or 16-bit memory interface with optional ECC. |
| 36 | * |
| 37 | * o ECC support includes: |
| 38 | * |
| 39 | * - 4-bit SEC/DED |
| 40 | * - Aligned-nibble error detect |
| 41 | * - Bypass mode |
| 42 | * |
| 43 | * - Two (2) memory banks/ranks. |
| 44 | * - Up to 1 GiB per bank/rank in 32-bit mode and up to 512 MiB per |
| 45 | * bank/rank in 16-bit mode. |
| 46 | * |
| 47 | * As realized in the 440SP and 440SPe, this controller changes/adds: |
| 48 | * |
| 49 | * - 64-bit or 32-bit memory interface with optional ECC. |
| 50 | * |
| 51 | * o ECC support includes: |
| 52 | * |
| 53 | * - 8-bit SEC/DED |
| 54 | * - Aligned-nibble error detect |
| 55 | * - Bypass mode |
| 56 | * |
| 57 | * - Up to 4 GiB per bank/rank in 64-bit mode and up to 2 GiB |
| 58 | * per bank/rank in 32-bit mode. |
| 59 | * |
| 60 | * As realized in the 460EX and 460GT, this controller changes/adds: |
| 61 | * |
| 62 | * - 64-bit or 32-bit memory interface with optional ECC. |
| 63 | * |
| 64 | * o ECC support includes: |
| 65 | * |
| 66 | * - 8-bit SEC/DED |
| 67 | * - Aligned-nibble error detect |
| 68 | * - Bypass mode |
| 69 | * |
| 70 | * - Four (4) memory banks/ranks. |
| 71 | * - Up to 16 GiB per bank/rank in 64-bit mode and up to 8 GiB |
| 72 | * per bank/rank in 32-bit mode. |
| 73 | * |
| 74 | * At present, this driver has ONLY been tested against the controller |
| 75 | * realization in the 405EX[r] on the AMCC Kilauea and Haleakala |
| 76 | * boards (256 MiB w/o ECC memory soldered onto the board) and a |
| 77 | * proprietary board based on those designs (128 MiB ECC memory, also |
| 78 | * soldered onto the board). |
| 79 | * |
| 80 | * Dynamic feature detection and handling needs to be added for the |
| 81 | * other realizations of this controller listed above. |
| 82 | * |
| 83 | * Eventually, this driver will likely be adapted to the above variant |
| 84 | * realizations of this controller as well as broken apart to handle |
| 85 | * the other known ECC-capable controllers prevalent in other 4xx |
| 86 | * processors: |
| 87 | * |
| 88 | * - IBM SDRAM (405GP, 405CR and 405EP) "ibm,sdram-4xx" |
| 89 | * - IBM DDR1 (440GP, 440GX, 440EP and 440GR) "ibm,sdram-4xx-ddr" |
| 90 | * - Denali DDR1/DDR2 (440EPX and 440GRX) "denali,sdram-4xx-ddr2" |
| 91 | * |
| 92 | * For this controller, unfortunately, correctable errors report |
| 93 | * nothing more than the beat/cycle and byte/lane the correction |
| 94 | * occurred on and the check bit group that covered the error. |
| 95 | * |
| 96 | * In contrast, uncorrectable errors also report the failing address, |
| 97 | * the bus master and the transaction direction (i.e. read or write) |
| 98 | * |
| 99 | * Regardless of whether the error is a CE or a UE, we report the |
| 100 | * following pieces of information in the driver-unique message to the |
| 101 | * EDAC subsystem: |
| 102 | * |
| 103 | * - Device tree path |
| 104 | * - Bank(s) |
| 105 | * - Check bit error group |
| 106 | * - Beat(s)/lane(s) |
| 107 | */ |
| 108 | |
| 109 | /* Preprocessor Definitions */ |
| 110 | |
| 111 | #define EDAC_OPSTATE_INT_STR "interrupt" |
| 112 | #define EDAC_OPSTATE_POLL_STR "polled" |
| 113 | #define EDAC_OPSTATE_UNKNOWN_STR "unknown" |
| 114 | |
| 115 | #define PPC4XX_EDAC_MODULE_NAME "ppc4xx_edac" |
Michal Marek | 152ba39 | 2011-04-01 12:41:20 +0200 | [diff] [blame] | 116 | #define PPC4XX_EDAC_MODULE_REVISION "v1.0.0" |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 117 | |
| 118 | #define PPC4XX_EDAC_MESSAGE_SIZE 256 |
| 119 | |
| 120 | /* |
| 121 | * Kernel logging without an EDAC instance |
| 122 | */ |
| 123 | #define ppc4xx_edac_printk(level, fmt, arg...) \ |
| 124 | edac_printk(level, "PPC4xx MC", fmt, ##arg) |
| 125 | |
| 126 | /* |
| 127 | * Kernel logging with an EDAC instance |
| 128 | */ |
| 129 | #define ppc4xx_edac_mc_printk(level, mci, fmt, arg...) \ |
| 130 | edac_mc_chipset_printk(mci, level, "PPC4xx", fmt, ##arg) |
| 131 | |
| 132 | /* |
| 133 | * Macros to convert bank configuration size enumerations into MiB and |
| 134 | * page values. |
| 135 | */ |
| 136 | #define SDRAM_MBCF_SZ_MiB_MIN 4 |
| 137 | #define SDRAM_MBCF_SZ_TO_MiB(n) (SDRAM_MBCF_SZ_MiB_MIN \ |
| 138 | << (SDRAM_MBCF_SZ_DECODE(n))) |
| 139 | #define SDRAM_MBCF_SZ_TO_PAGES(n) (SDRAM_MBCF_SZ_MiB_MIN \ |
| 140 | << (20 - PAGE_SHIFT + \ |
| 141 | SDRAM_MBCF_SZ_DECODE(n))) |
| 142 | |
| 143 | /* |
| 144 | * The ibm,sdram-4xx-ddr2 Device Control Registers (DCRs) are |
Justin P. Mattock | 42b2aa8 | 2011-11-28 20:31:00 -0800 | [diff] [blame] | 145 | * indirectly accessed and have a base and length defined by the |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 146 | * device tree. The base can be anything; however, we expect the |
| 147 | * length to be precisely two registers, the first for the address |
| 148 | * window and the second for the data window. |
| 149 | */ |
| 150 | #define SDRAM_DCR_RESOURCE_LEN 2 |
| 151 | #define SDRAM_DCR_ADDR_OFFSET 0 |
| 152 | #define SDRAM_DCR_DATA_OFFSET 1 |
| 153 | |
| 154 | /* |
| 155 | * Device tree interrupt indices |
| 156 | */ |
| 157 | #define INTMAP_ECCDED_INDEX 0 /* Double-bit Error Detect */ |
| 158 | #define INTMAP_ECCSEC_INDEX 1 /* Single-bit Error Correct */ |
| 159 | |
| 160 | /* Type Definitions */ |
| 161 | |
| 162 | /* |
| 163 | * PPC4xx SDRAM memory controller private instance data |
| 164 | */ |
| 165 | struct ppc4xx_edac_pdata { |
| 166 | dcr_host_t dcr_host; /* Indirect DCR address/data window mapping */ |
| 167 | struct { |
| 168 | int sec; /* Single-bit correctable error IRQ assigned */ |
| 169 | int ded; /* Double-bit detectable error IRQ assigned */ |
| 170 | } irqs; |
| 171 | }; |
| 172 | |
| 173 | /* |
| 174 | * Various status data gathered and manipulated when checking and |
| 175 | * reporting ECC status. |
| 176 | */ |
| 177 | struct ppc4xx_ecc_status { |
| 178 | u32 ecces; |
| 179 | u32 besr; |
| 180 | u32 bearh; |
| 181 | u32 bearl; |
| 182 | u32 wmirq; |
| 183 | }; |
| 184 | |
| 185 | /* Function Prototypes */ |
| 186 | |
Mauro Carvalho Chehab | b877763 | 2012-01-31 16:36:08 -0300 | [diff] [blame] | 187 | static int ppc4xx_edac_probe(struct platform_device *device); |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 188 | static int ppc4xx_edac_remove(struct platform_device *device); |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 189 | |
| 190 | /* Global Variables */ |
| 191 | |
| 192 | /* |
| 193 | * Device tree node type and compatible tuples this driver can match |
| 194 | * on. |
| 195 | */ |
| 196 | static struct of_device_id ppc4xx_edac_match[] = { |
| 197 | { |
| 198 | .compatible = "ibm,sdram-4xx-ddr2" |
| 199 | }, |
| 200 | { } |
| 201 | }; |
| 202 | |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 203 | static struct platform_driver ppc4xx_edac_driver = { |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 204 | .probe = ppc4xx_edac_probe, |
| 205 | .remove = ppc4xx_edac_remove, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 206 | .driver = { |
| 207 | .owner = THIS_MODULE, |
Mike Williams | e57b708 | 2011-07-07 06:09:58 +0000 | [diff] [blame] | 208 | .name = PPC4XX_EDAC_MODULE_NAME, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 209 | .of_match_table = ppc4xx_edac_match, |
| 210 | }, |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | /* |
| 214 | * TODO: The row and channel parameters likely need to be dynamically |
| 215 | * set based on the aforementioned variant controller realizations. |
| 216 | */ |
| 217 | static const unsigned ppc4xx_edac_nr_csrows = 2; |
| 218 | static const unsigned ppc4xx_edac_nr_chans = 1; |
| 219 | |
| 220 | /* |
| 221 | * Strings associated with PLB master IDs capable of being posted in |
| 222 | * SDRAM_BESR or SDRAM_WMIRQ on uncorrectable ECC errors. |
| 223 | */ |
| 224 | static const char * const ppc4xx_plb_masters[9] = { |
| 225 | [SDRAM_PLB_M0ID_ICU] = "ICU", |
| 226 | [SDRAM_PLB_M0ID_PCIE0] = "PCI-E 0", |
| 227 | [SDRAM_PLB_M0ID_PCIE1] = "PCI-E 1", |
| 228 | [SDRAM_PLB_M0ID_DMA] = "DMA", |
| 229 | [SDRAM_PLB_M0ID_DCU] = "DCU", |
| 230 | [SDRAM_PLB_M0ID_OPB] = "OPB", |
| 231 | [SDRAM_PLB_M0ID_MAL] = "MAL", |
| 232 | [SDRAM_PLB_M0ID_SEC] = "SEC", |
| 233 | [SDRAM_PLB_M0ID_AHB] = "AHB" |
| 234 | }; |
| 235 | |
| 236 | /** |
| 237 | * mfsdram - read and return controller register data |
| 238 | * @dcr_host: A pointer to the DCR mapping. |
| 239 | * @idcr_n: The indirect DCR register to read. |
| 240 | * |
| 241 | * This routine reads and returns the data associated with the |
| 242 | * controller's specified indirect DCR register. |
| 243 | * |
| 244 | * Returns the read data. |
| 245 | */ |
| 246 | static inline u32 |
| 247 | mfsdram(const dcr_host_t *dcr_host, unsigned int idcr_n) |
| 248 | { |
| 249 | return __mfdcri(dcr_host->base + SDRAM_DCR_ADDR_OFFSET, |
| 250 | dcr_host->base + SDRAM_DCR_DATA_OFFSET, |
| 251 | idcr_n); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * mtsdram - write controller register data |
| 256 | * @dcr_host: A pointer to the DCR mapping. |
| 257 | * @idcr_n: The indirect DCR register to write. |
| 258 | * @value: The data to write. |
| 259 | * |
| 260 | * This routine writes the provided data to the controller's specified |
| 261 | * indirect DCR register. |
| 262 | */ |
| 263 | static inline void |
| 264 | mtsdram(const dcr_host_t *dcr_host, unsigned int idcr_n, u32 value) |
| 265 | { |
| 266 | return __mtdcri(dcr_host->base + SDRAM_DCR_ADDR_OFFSET, |
| 267 | dcr_host->base + SDRAM_DCR_DATA_OFFSET, |
| 268 | idcr_n, |
| 269 | value); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * ppc4xx_edac_check_bank_error - check a bank for an ECC bank error |
| 274 | * @status: A pointer to the ECC status structure to check for an |
| 275 | * ECC bank error. |
| 276 | * @bank: The bank to check for an ECC error. |
| 277 | * |
| 278 | * This routine determines whether the specified bank has an ECC |
| 279 | * error. |
| 280 | * |
| 281 | * Returns true if the specified bank has an ECC error; otherwise, |
| 282 | * false. |
| 283 | */ |
| 284 | static bool |
| 285 | ppc4xx_edac_check_bank_error(const struct ppc4xx_ecc_status *status, |
| 286 | unsigned int bank) |
| 287 | { |
| 288 | switch (bank) { |
| 289 | case 0: |
| 290 | return status->ecces & SDRAM_ECCES_BK0ER; |
| 291 | case 1: |
| 292 | return status->ecces & SDRAM_ECCES_BK1ER; |
| 293 | default: |
| 294 | return false; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * ppc4xx_edac_generate_bank_message - generate interpretted bank status message |
| 300 | * @mci: A pointer to the EDAC memory controller instance associated |
| 301 | * with the bank message being generated. |
| 302 | * @status: A pointer to the ECC status structure to generate the |
| 303 | * message from. |
| 304 | * @buffer: A pointer to the buffer in which to generate the |
| 305 | * message. |
| 306 | * @size: The size, in bytes, of space available in buffer. |
| 307 | * |
| 308 | * This routine generates to the provided buffer the portion of the |
| 309 | * driver-unique report message associated with the ECCESS[BKNER] |
| 310 | * field of the specified ECC status. |
| 311 | * |
| 312 | * Returns the number of characters generated on success; otherwise, < |
| 313 | * 0 on error. |
| 314 | */ |
| 315 | static int |
| 316 | ppc4xx_edac_generate_bank_message(const struct mem_ctl_info *mci, |
| 317 | const struct ppc4xx_ecc_status *status, |
| 318 | char *buffer, |
| 319 | size_t size) |
| 320 | { |
| 321 | int n, total = 0; |
| 322 | unsigned int row, rows; |
| 323 | |
| 324 | n = snprintf(buffer, size, "%s: Banks: ", mci->dev_name); |
| 325 | |
| 326 | if (n < 0 || n >= size) |
| 327 | goto fail; |
| 328 | |
| 329 | buffer += n; |
| 330 | size -= n; |
| 331 | total += n; |
| 332 | |
| 333 | for (rows = 0, row = 0; row < mci->nr_csrows; row++) { |
| 334 | if (ppc4xx_edac_check_bank_error(status, row)) { |
| 335 | n = snprintf(buffer, size, "%s%u", |
| 336 | (rows++ ? ", " : ""), row); |
| 337 | |
| 338 | if (n < 0 || n >= size) |
| 339 | goto fail; |
| 340 | |
| 341 | buffer += n; |
| 342 | size -= n; |
| 343 | total += n; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | n = snprintf(buffer, size, "%s; ", rows ? "" : "None"); |
| 348 | |
| 349 | if (n < 0 || n >= size) |
| 350 | goto fail; |
| 351 | |
| 352 | buffer += n; |
| 353 | size -= n; |
| 354 | total += n; |
| 355 | |
| 356 | fail: |
| 357 | return total; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * ppc4xx_edac_generate_checkbit_message - generate interpretted checkbit message |
| 362 | * @mci: A pointer to the EDAC memory controller instance associated |
| 363 | * with the checkbit message being generated. |
| 364 | * @status: A pointer to the ECC status structure to generate the |
| 365 | * message from. |
| 366 | * @buffer: A pointer to the buffer in which to generate the |
| 367 | * message. |
| 368 | * @size: The size, in bytes, of space available in buffer. |
| 369 | * |
| 370 | * This routine generates to the provided buffer the portion of the |
| 371 | * driver-unique report message associated with the ECCESS[CKBER] |
| 372 | * field of the specified ECC status. |
| 373 | * |
| 374 | * Returns the number of characters generated on success; otherwise, < |
| 375 | * 0 on error. |
| 376 | */ |
| 377 | static int |
| 378 | ppc4xx_edac_generate_checkbit_message(const struct mem_ctl_info *mci, |
| 379 | const struct ppc4xx_ecc_status *status, |
| 380 | char *buffer, |
| 381 | size_t size) |
| 382 | { |
| 383 | const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; |
| 384 | const char *ckber = NULL; |
| 385 | |
| 386 | switch (status->ecces & SDRAM_ECCES_CKBER_MASK) { |
| 387 | case SDRAM_ECCES_CKBER_NONE: |
| 388 | ckber = "None"; |
| 389 | break; |
| 390 | case SDRAM_ECCES_CKBER_32_ECC_0_3: |
| 391 | ckber = "ECC0:3"; |
| 392 | break; |
| 393 | case SDRAM_ECCES_CKBER_32_ECC_4_8: |
| 394 | switch (mfsdram(&pdata->dcr_host, SDRAM_MCOPT1) & |
| 395 | SDRAM_MCOPT1_WDTH_MASK) { |
| 396 | case SDRAM_MCOPT1_WDTH_16: |
| 397 | ckber = "ECC0:3"; |
| 398 | break; |
| 399 | case SDRAM_MCOPT1_WDTH_32: |
| 400 | ckber = "ECC4:8"; |
| 401 | break; |
| 402 | default: |
| 403 | ckber = "Unknown"; |
| 404 | break; |
| 405 | } |
| 406 | break; |
| 407 | case SDRAM_ECCES_CKBER_32_ECC_0_8: |
| 408 | ckber = "ECC0:8"; |
| 409 | break; |
| 410 | default: |
| 411 | ckber = "Unknown"; |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | return snprintf(buffer, size, "Checkbit Error: %s", ckber); |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * ppc4xx_edac_generate_lane_message - generate interpretted byte lane message |
| 420 | * @mci: A pointer to the EDAC memory controller instance associated |
| 421 | * with the byte lane message being generated. |
| 422 | * @status: A pointer to the ECC status structure to generate the |
| 423 | * message from. |
| 424 | * @buffer: A pointer to the buffer in which to generate the |
| 425 | * message. |
| 426 | * @size: The size, in bytes, of space available in buffer. |
| 427 | * |
| 428 | * This routine generates to the provided buffer the portion of the |
| 429 | * driver-unique report message associated with the ECCESS[BNCE] |
| 430 | * field of the specified ECC status. |
| 431 | * |
| 432 | * Returns the number of characters generated on success; otherwise, < |
| 433 | * 0 on error. |
| 434 | */ |
| 435 | static int |
| 436 | ppc4xx_edac_generate_lane_message(const struct mem_ctl_info *mci, |
| 437 | const struct ppc4xx_ecc_status *status, |
| 438 | char *buffer, |
| 439 | size_t size) |
| 440 | { |
| 441 | int n, total = 0; |
| 442 | unsigned int lane, lanes; |
| 443 | const unsigned int first_lane = 0; |
| 444 | const unsigned int lane_count = 16; |
| 445 | |
| 446 | n = snprintf(buffer, size, "; Byte Lane Errors: "); |
| 447 | |
| 448 | if (n < 0 || n >= size) |
| 449 | goto fail; |
| 450 | |
| 451 | buffer += n; |
| 452 | size -= n; |
| 453 | total += n; |
| 454 | |
| 455 | for (lanes = 0, lane = first_lane; lane < lane_count; lane++) { |
| 456 | if ((status->ecces & SDRAM_ECCES_BNCE_ENCODE(lane)) != 0) { |
| 457 | n = snprintf(buffer, size, |
| 458 | "%s%u", |
| 459 | (lanes++ ? ", " : ""), lane); |
| 460 | |
| 461 | if (n < 0 || n >= size) |
| 462 | goto fail; |
| 463 | |
| 464 | buffer += n; |
| 465 | size -= n; |
| 466 | total += n; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | n = snprintf(buffer, size, "%s; ", lanes ? "" : "None"); |
| 471 | |
| 472 | if (n < 0 || n >= size) |
| 473 | goto fail; |
| 474 | |
| 475 | buffer += n; |
| 476 | size -= n; |
| 477 | total += n; |
| 478 | |
| 479 | fail: |
| 480 | return total; |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * ppc4xx_edac_generate_ecc_message - generate interpretted ECC status message |
| 485 | * @mci: A pointer to the EDAC memory controller instance associated |
| 486 | * with the ECCES message being generated. |
| 487 | * @status: A pointer to the ECC status structure to generate the |
| 488 | * message from. |
| 489 | * @buffer: A pointer to the buffer in which to generate the |
| 490 | * message. |
| 491 | * @size: The size, in bytes, of space available in buffer. |
| 492 | * |
| 493 | * This routine generates to the provided buffer the portion of the |
| 494 | * driver-unique report message associated with the ECCESS register of |
| 495 | * the specified ECC status. |
| 496 | * |
| 497 | * Returns the number of characters generated on success; otherwise, < |
| 498 | * 0 on error. |
| 499 | */ |
| 500 | static int |
| 501 | ppc4xx_edac_generate_ecc_message(const struct mem_ctl_info *mci, |
| 502 | const struct ppc4xx_ecc_status *status, |
| 503 | char *buffer, |
| 504 | size_t size) |
| 505 | { |
| 506 | int n, total = 0; |
| 507 | |
| 508 | n = ppc4xx_edac_generate_bank_message(mci, status, buffer, size); |
| 509 | |
| 510 | if (n < 0 || n >= size) |
| 511 | goto fail; |
| 512 | |
| 513 | buffer += n; |
| 514 | size -= n; |
| 515 | total += n; |
| 516 | |
| 517 | n = ppc4xx_edac_generate_checkbit_message(mci, status, buffer, size); |
| 518 | |
| 519 | if (n < 0 || n >= size) |
| 520 | goto fail; |
| 521 | |
| 522 | buffer += n; |
| 523 | size -= n; |
| 524 | total += n; |
| 525 | |
| 526 | n = ppc4xx_edac_generate_lane_message(mci, status, buffer, size); |
| 527 | |
| 528 | if (n < 0 || n >= size) |
| 529 | goto fail; |
| 530 | |
| 531 | buffer += n; |
| 532 | size -= n; |
| 533 | total += n; |
| 534 | |
| 535 | fail: |
| 536 | return total; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * ppc4xx_edac_generate_plb_message - generate interpretted PLB status message |
| 541 | * @mci: A pointer to the EDAC memory controller instance associated |
| 542 | * with the PLB message being generated. |
| 543 | * @status: A pointer to the ECC status structure to generate the |
| 544 | * message from. |
| 545 | * @buffer: A pointer to the buffer in which to generate the |
| 546 | * message. |
| 547 | * @size: The size, in bytes, of space available in buffer. |
| 548 | * |
| 549 | * This routine generates to the provided buffer the portion of the |
| 550 | * driver-unique report message associated with the PLB-related BESR |
| 551 | * and/or WMIRQ registers of the specified ECC status. |
| 552 | * |
| 553 | * Returns the number of characters generated on success; otherwise, < |
| 554 | * 0 on error. |
| 555 | */ |
| 556 | static int |
| 557 | ppc4xx_edac_generate_plb_message(const struct mem_ctl_info *mci, |
| 558 | const struct ppc4xx_ecc_status *status, |
| 559 | char *buffer, |
| 560 | size_t size) |
| 561 | { |
| 562 | unsigned int master; |
| 563 | bool read; |
| 564 | |
| 565 | if ((status->besr & SDRAM_BESR_MASK) == 0) |
| 566 | return 0; |
| 567 | |
| 568 | if ((status->besr & SDRAM_BESR_M0ET_MASK) == SDRAM_BESR_M0ET_NONE) |
| 569 | return 0; |
| 570 | |
| 571 | read = ((status->besr & SDRAM_BESR_M0RW_MASK) == SDRAM_BESR_M0RW_READ); |
| 572 | |
| 573 | master = SDRAM_BESR_M0ID_DECODE(status->besr); |
| 574 | |
| 575 | return snprintf(buffer, size, |
| 576 | "%s error w/ PLB master %u \"%s\"; ", |
| 577 | (read ? "Read" : "Write"), |
| 578 | master, |
| 579 | (((master >= SDRAM_PLB_M0ID_FIRST) && |
| 580 | (master <= SDRAM_PLB_M0ID_LAST)) ? |
| 581 | ppc4xx_plb_masters[master] : "UNKNOWN")); |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * ppc4xx_edac_generate_message - generate interpretted status message |
| 586 | * @mci: A pointer to the EDAC memory controller instance associated |
| 587 | * with the driver-unique message being generated. |
| 588 | * @status: A pointer to the ECC status structure to generate the |
| 589 | * message from. |
| 590 | * @buffer: A pointer to the buffer in which to generate the |
| 591 | * message. |
| 592 | * @size: The size, in bytes, of space available in buffer. |
| 593 | * |
| 594 | * This routine generates to the provided buffer the driver-unique |
| 595 | * EDAC report message from the specified ECC status. |
| 596 | */ |
| 597 | static void |
| 598 | ppc4xx_edac_generate_message(const struct mem_ctl_info *mci, |
| 599 | const struct ppc4xx_ecc_status *status, |
| 600 | char *buffer, |
| 601 | size_t size) |
| 602 | { |
| 603 | int n; |
| 604 | |
| 605 | if (buffer == NULL || size == 0) |
| 606 | return; |
| 607 | |
| 608 | n = ppc4xx_edac_generate_ecc_message(mci, status, buffer, size); |
| 609 | |
| 610 | if (n < 0 || n >= size) |
| 611 | return; |
| 612 | |
| 613 | buffer += n; |
| 614 | size -= n; |
| 615 | |
| 616 | ppc4xx_edac_generate_plb_message(mci, status, buffer, size); |
| 617 | } |
| 618 | |
| 619 | #ifdef DEBUG |
| 620 | /** |
| 621 | * ppc4xx_ecc_dump_status - dump controller ECC status registers |
| 622 | * @mci: A pointer to the EDAC memory controller instance |
| 623 | * associated with the status being dumped. |
| 624 | * @status: A pointer to the ECC status structure to generate the |
| 625 | * dump from. |
| 626 | * |
| 627 | * This routine dumps to the kernel log buffer the raw and |
| 628 | * interpretted specified ECC status. |
| 629 | */ |
| 630 | static void |
| 631 | ppc4xx_ecc_dump_status(const struct mem_ctl_info *mci, |
| 632 | const struct ppc4xx_ecc_status *status) |
| 633 | { |
| 634 | char message[PPC4XX_EDAC_MESSAGE_SIZE]; |
| 635 | |
| 636 | ppc4xx_edac_generate_message(mci, status, message, sizeof(message)); |
| 637 | |
| 638 | ppc4xx_edac_mc_printk(KERN_INFO, mci, |
| 639 | "\n" |
| 640 | "\tECCES: 0x%08x\n" |
| 641 | "\tWMIRQ: 0x%08x\n" |
| 642 | "\tBESR: 0x%08x\n" |
| 643 | "\tBEAR: 0x%08x%08x\n" |
| 644 | "\t%s\n", |
| 645 | status->ecces, |
| 646 | status->wmirq, |
| 647 | status->besr, |
| 648 | status->bearh, |
| 649 | status->bearl, |
| 650 | message); |
| 651 | } |
| 652 | #endif /* DEBUG */ |
| 653 | |
| 654 | /** |
| 655 | * ppc4xx_ecc_get_status - get controller ECC status |
| 656 | * @mci: A pointer to the EDAC memory controller instance |
| 657 | * associated with the status being retrieved. |
| 658 | * @status: A pointer to the ECC status structure to populate the |
| 659 | * ECC status with. |
| 660 | * |
| 661 | * This routine reads and masks, as appropriate, all the relevant |
| 662 | * status registers that deal with ibm,sdram-4xx-ddr2 ECC errors. |
| 663 | * While we read all of them, for correctable errors, we only expect |
| 664 | * to deal with ECCES. For uncorrectable errors, we expect to deal |
| 665 | * with all of them. |
| 666 | */ |
| 667 | static void |
| 668 | ppc4xx_ecc_get_status(const struct mem_ctl_info *mci, |
| 669 | struct ppc4xx_ecc_status *status) |
| 670 | { |
| 671 | const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; |
| 672 | const dcr_host_t *dcr_host = &pdata->dcr_host; |
| 673 | |
| 674 | status->ecces = mfsdram(dcr_host, SDRAM_ECCES) & SDRAM_ECCES_MASK; |
| 675 | status->wmirq = mfsdram(dcr_host, SDRAM_WMIRQ) & SDRAM_WMIRQ_MASK; |
| 676 | status->besr = mfsdram(dcr_host, SDRAM_BESR) & SDRAM_BESR_MASK; |
| 677 | status->bearl = mfsdram(dcr_host, SDRAM_BEARL); |
| 678 | status->bearh = mfsdram(dcr_host, SDRAM_BEARH); |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * ppc4xx_ecc_clear_status - clear controller ECC status |
| 683 | * @mci: A pointer to the EDAC memory controller instance |
| 684 | * associated with the status being cleared. |
| 685 | * @status: A pointer to the ECC status structure containing the |
| 686 | * values to write to clear the ECC status. |
| 687 | * |
| 688 | * This routine clears--by writing the masked (as appropriate) status |
| 689 | * values back to--the status registers that deal with |
| 690 | * ibm,sdram-4xx-ddr2 ECC errors. |
| 691 | */ |
| 692 | static void |
| 693 | ppc4xx_ecc_clear_status(const struct mem_ctl_info *mci, |
| 694 | const struct ppc4xx_ecc_status *status) |
| 695 | { |
| 696 | const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; |
| 697 | const dcr_host_t *dcr_host = &pdata->dcr_host; |
| 698 | |
| 699 | mtsdram(dcr_host, SDRAM_ECCES, status->ecces & SDRAM_ECCES_MASK); |
| 700 | mtsdram(dcr_host, SDRAM_WMIRQ, status->wmirq & SDRAM_WMIRQ_MASK); |
| 701 | mtsdram(dcr_host, SDRAM_BESR, status->besr & SDRAM_BESR_MASK); |
| 702 | mtsdram(dcr_host, SDRAM_BEARL, 0); |
| 703 | mtsdram(dcr_host, SDRAM_BEARH, 0); |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * ppc4xx_edac_handle_ce - handle controller correctable ECC error (CE) |
| 708 | * @mci: A pointer to the EDAC memory controller instance |
| 709 | * associated with the correctable error being handled and reported. |
| 710 | * @status: A pointer to the ECC status structure associated with |
| 711 | * the correctable error being handled and reported. |
| 712 | * |
| 713 | * This routine handles an ibm,sdram-4xx-ddr2 controller ECC |
| 714 | * correctable error. Per the aforementioned discussion, there's not |
| 715 | * enough status available to use the full EDAC correctable error |
| 716 | * interface, so we just pass driver-unique message to the "no info" |
| 717 | * interface. |
| 718 | */ |
| 719 | static void |
| 720 | ppc4xx_edac_handle_ce(struct mem_ctl_info *mci, |
| 721 | const struct ppc4xx_ecc_status *status) |
| 722 | { |
| 723 | int row; |
| 724 | char message[PPC4XX_EDAC_MESSAGE_SIZE]; |
| 725 | |
| 726 | ppc4xx_edac_generate_message(mci, status, message, sizeof(message)); |
| 727 | |
| 728 | for (row = 0; row < mci->nr_csrows; row++) |
| 729 | if (ppc4xx_edac_check_bank_error(status, row)) |
| 730 | edac_mc_handle_ce_no_info(mci, message); |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * ppc4xx_edac_handle_ue - handle controller uncorrectable ECC error (UE) |
| 735 | * @mci: A pointer to the EDAC memory controller instance |
| 736 | * associated with the uncorrectable error being handled and |
| 737 | * reported. |
| 738 | * @status: A pointer to the ECC status structure associated with |
| 739 | * the uncorrectable error being handled and reported. |
| 740 | * |
| 741 | * This routine handles an ibm,sdram-4xx-ddr2 controller ECC |
| 742 | * uncorrectable error. |
| 743 | */ |
| 744 | static void |
| 745 | ppc4xx_edac_handle_ue(struct mem_ctl_info *mci, |
| 746 | const struct ppc4xx_ecc_status *status) |
| 747 | { |
| 748 | const u64 bear = ((u64)status->bearh << 32 | status->bearl); |
| 749 | const unsigned long page = bear >> PAGE_SHIFT; |
| 750 | const unsigned long offset = bear & ~PAGE_MASK; |
| 751 | int row; |
| 752 | char message[PPC4XX_EDAC_MESSAGE_SIZE]; |
| 753 | |
| 754 | ppc4xx_edac_generate_message(mci, status, message, sizeof(message)); |
| 755 | |
| 756 | for (row = 0; row < mci->nr_csrows; row++) |
| 757 | if (ppc4xx_edac_check_bank_error(status, row)) |
| 758 | edac_mc_handle_ue(mci, page, offset, row, message); |
| 759 | } |
| 760 | |
| 761 | /** |
| 762 | * ppc4xx_edac_check - check controller for ECC errors |
| 763 | * @mci: A pointer to the EDAC memory controller instance |
| 764 | * associated with the ibm,sdram-4xx-ddr2 controller being |
| 765 | * checked. |
| 766 | * |
| 767 | * This routine is used to check and post ECC errors and is called by |
| 768 | * both the EDAC polling thread and this driver's CE and UE interrupt |
| 769 | * handler. |
| 770 | */ |
| 771 | static void |
| 772 | ppc4xx_edac_check(struct mem_ctl_info *mci) |
| 773 | { |
| 774 | #ifdef DEBUG |
| 775 | static unsigned int count; |
| 776 | #endif |
| 777 | struct ppc4xx_ecc_status status; |
| 778 | |
| 779 | ppc4xx_ecc_get_status(mci, &status); |
| 780 | |
| 781 | #ifdef DEBUG |
| 782 | if (count++ % 30 == 0) |
| 783 | ppc4xx_ecc_dump_status(mci, &status); |
| 784 | #endif |
| 785 | |
| 786 | if (status.ecces & SDRAM_ECCES_UE) |
| 787 | ppc4xx_edac_handle_ue(mci, &status); |
| 788 | |
| 789 | if (status.ecces & SDRAM_ECCES_CE) |
| 790 | ppc4xx_edac_handle_ce(mci, &status); |
| 791 | |
| 792 | ppc4xx_ecc_clear_status(mci, &status); |
| 793 | } |
| 794 | |
| 795 | /** |
| 796 | * ppc4xx_edac_isr - SEC (CE) and DED (UE) interrupt service routine |
| 797 | * @irq: The virtual interrupt number being serviced. |
| 798 | * @dev_id: A pointer to the EDAC memory controller instance |
| 799 | * associated with the interrupt being handled. |
| 800 | * |
| 801 | * This routine implements the interrupt handler for both correctable |
| 802 | * (CE) and uncorrectable (UE) ECC errors for the ibm,sdram-4xx-ddr2 |
| 803 | * controller. It simply calls through to the same routine used during |
| 804 | * polling to check, report and clear the ECC status. |
| 805 | * |
| 806 | * Unconditionally returns IRQ_HANDLED. |
| 807 | */ |
| 808 | static irqreturn_t |
| 809 | ppc4xx_edac_isr(int irq, void *dev_id) |
| 810 | { |
| 811 | struct mem_ctl_info *mci = dev_id; |
| 812 | |
| 813 | ppc4xx_edac_check(mci); |
| 814 | |
| 815 | return IRQ_HANDLED; |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * ppc4xx_edac_get_dtype - return the controller memory width |
| 820 | * @mcopt1: The 32-bit Memory Controller Option 1 register value |
| 821 | * currently set for the controller, from which the width |
| 822 | * is derived. |
| 823 | * |
| 824 | * This routine returns the EDAC device type width appropriate for the |
| 825 | * current controller configuration. |
| 826 | * |
| 827 | * TODO: This needs to be conditioned dynamically through feature |
| 828 | * flags or some such when other controller variants are supported as |
| 829 | * the 405EX[r] is 16-/32-bit and the others are 32-/64-bit with the |
| 830 | * 16- and 64-bit field definition/value/enumeration (b1) overloaded |
| 831 | * among them. |
| 832 | * |
| 833 | * Returns a device type width enumeration. |
| 834 | */ |
| 835 | static enum dev_type __devinit |
| 836 | ppc4xx_edac_get_dtype(u32 mcopt1) |
| 837 | { |
| 838 | switch (mcopt1 & SDRAM_MCOPT1_WDTH_MASK) { |
| 839 | case SDRAM_MCOPT1_WDTH_16: |
| 840 | return DEV_X2; |
| 841 | case SDRAM_MCOPT1_WDTH_32: |
| 842 | return DEV_X4; |
| 843 | default: |
| 844 | return DEV_UNKNOWN; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * ppc4xx_edac_get_mtype - return controller memory type |
| 850 | * @mcopt1: The 32-bit Memory Controller Option 1 register value |
| 851 | * currently set for the controller, from which the memory type |
| 852 | * is derived. |
| 853 | * |
| 854 | * This routine returns the EDAC memory type appropriate for the |
| 855 | * current controller configuration. |
| 856 | * |
| 857 | * Returns a memory type enumeration. |
| 858 | */ |
| 859 | static enum mem_type __devinit |
| 860 | ppc4xx_edac_get_mtype(u32 mcopt1) |
| 861 | { |
| 862 | bool rden = ((mcopt1 & SDRAM_MCOPT1_RDEN_MASK) == SDRAM_MCOPT1_RDEN); |
| 863 | |
| 864 | switch (mcopt1 & SDRAM_MCOPT1_DDR_TYPE_MASK) { |
| 865 | case SDRAM_MCOPT1_DDR2_TYPE: |
| 866 | return rden ? MEM_RDDR2 : MEM_DDR2; |
| 867 | case SDRAM_MCOPT1_DDR1_TYPE: |
| 868 | return rden ? MEM_RDDR : MEM_DDR; |
| 869 | default: |
| 870 | return MEM_UNKNOWN; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | /** |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 875 | * ppc4xx_edac_init_csrows - initialize driver instance rows |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 876 | * @mci: A pointer to the EDAC memory controller instance |
| 877 | * associated with the ibm,sdram-4xx-ddr2 controller for which |
| 878 | * the csrows (i.e. banks/ranks) are being initialized. |
| 879 | * @mcopt1: The 32-bit Memory Controller Option 1 register value |
| 880 | * currently set for the controller, from which bank width |
| 881 | * and memory typ information is derived. |
| 882 | * |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 883 | * This routine initializes the virtual "chip select rows" associated |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 884 | * with the EDAC memory controller instance. An ibm,sdram-4xx-ddr2 |
| 885 | * controller bank/rank is mapped to a row. |
| 886 | * |
| 887 | * Returns 0 if OK; otherwise, -EINVAL if the memory bank size |
| 888 | * configuration cannot be determined. |
| 889 | */ |
| 890 | static int __devinit |
| 891 | ppc4xx_edac_init_csrows(struct mem_ctl_info *mci, u32 mcopt1) |
| 892 | { |
| 893 | const struct ppc4xx_edac_pdata *pdata = mci->pvt_info; |
| 894 | int status = 0; |
| 895 | enum mem_type mtype; |
| 896 | enum dev_type dtype; |
| 897 | enum edac_type edac_mode; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 898 | int row, j; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 899 | u32 mbxcf, size, nr_pages; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 900 | |
| 901 | /* Establish the memory type and width */ |
| 902 | |
| 903 | mtype = ppc4xx_edac_get_mtype(mcopt1); |
| 904 | dtype = ppc4xx_edac_get_dtype(mcopt1); |
| 905 | |
| 906 | /* Establish EDAC mode */ |
| 907 | |
| 908 | if (mci->edac_cap & EDAC_FLAG_SECDED) |
| 909 | edac_mode = EDAC_SECDED; |
| 910 | else if (mci->edac_cap & EDAC_FLAG_EC) |
| 911 | edac_mode = EDAC_EC; |
| 912 | else |
| 913 | edac_mode = EDAC_NONE; |
| 914 | |
| 915 | /* |
| 916 | * Initialize each chip select row structure which correspond |
| 917 | * 1:1 with a controller bank/rank. |
| 918 | */ |
| 919 | |
| 920 | for (row = 0; row < mci->nr_csrows; row++) { |
| 921 | struct csrow_info *csi = &mci->csrows[row]; |
| 922 | |
| 923 | /* |
| 924 | * Get the configuration settings for this |
| 925 | * row/bank/rank and skip disabled banks. |
| 926 | */ |
| 927 | |
| 928 | mbxcf = mfsdram(&pdata->dcr_host, SDRAM_MBXCF(row)); |
| 929 | |
| 930 | if ((mbxcf & SDRAM_MBCF_BE_MASK) != SDRAM_MBCF_BE_ENABLE) |
| 931 | continue; |
| 932 | |
| 933 | /* Map the bank configuration size setting to pages. */ |
| 934 | |
| 935 | size = mbxcf & SDRAM_MBCF_SZ_MASK; |
| 936 | |
| 937 | switch (size) { |
| 938 | case SDRAM_MBCF_SZ_4MB: |
| 939 | case SDRAM_MBCF_SZ_8MB: |
| 940 | case SDRAM_MBCF_SZ_16MB: |
| 941 | case SDRAM_MBCF_SZ_32MB: |
| 942 | case SDRAM_MBCF_SZ_64MB: |
| 943 | case SDRAM_MBCF_SZ_128MB: |
| 944 | case SDRAM_MBCF_SZ_256MB: |
| 945 | case SDRAM_MBCF_SZ_512MB: |
| 946 | case SDRAM_MBCF_SZ_1GB: |
| 947 | case SDRAM_MBCF_SZ_2GB: |
| 948 | case SDRAM_MBCF_SZ_4GB: |
| 949 | case SDRAM_MBCF_SZ_8GB: |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 950 | nr_pages = SDRAM_MBCF_SZ_TO_PAGES(size); |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 951 | break; |
| 952 | default: |
| 953 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 954 | "Unrecognized memory bank %d " |
| 955 | "size 0x%08x\n", |
| 956 | row, SDRAM_MBCF_SZ_DECODE(size)); |
| 957 | status = -EINVAL; |
| 958 | goto done; |
| 959 | } |
| 960 | |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 961 | /* |
| 962 | * It's unclear exactly what grain should be set to |
| 963 | * here. The SDRAM_ECCES register allows resolution of |
| 964 | * an error down to a nibble which would potentially |
| 965 | * argue for a grain of '1' byte, even though we only |
| 966 | * know the associated address for uncorrectable |
| 967 | * errors. This value is not used at present for |
| 968 | * anything other than error reporting so getting it |
| 969 | * wrong should be of little consequence. Other |
| 970 | * possible values would be the PLB width (16), the |
| 971 | * page size (PAGE_SIZE) or the memory width (2 or 4). |
| 972 | */ |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 973 | for (j = 0; j < csi->nr_channels; j++) { |
| 974 | struct dimm_info *dimm = csi->channels[j].dimm; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 975 | |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 976 | dimm->nr_pages = nr_pages / csi->nr_channels; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 977 | dimm->grain = 1; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 978 | |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 979 | dimm->mtype = mtype; |
| 980 | dimm->dtype = dtype; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 981 | |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 982 | dimm->edac_mode = edac_mode; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 983 | } |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | done: |
| 987 | return status; |
| 988 | } |
| 989 | |
| 990 | /** |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 991 | * ppc4xx_edac_mc_init - initialize driver instance |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 992 | * @mci: A pointer to the EDAC memory controller instance being |
| 993 | * initialized. |
| 994 | * @op: A pointer to the OpenFirmware device tree node associated |
| 995 | * with the controller this EDAC instance is bound to. |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 996 | * @dcr_host: A pointer to the DCR data containing the DCR mapping |
| 997 | * for this controller instance. |
| 998 | * @mcopt1: The 32-bit Memory Controller Option 1 register value |
| 999 | * currently set for the controller, from which ECC capabilities |
| 1000 | * and scrub mode are derived. |
| 1001 | * |
| 1002 | * This routine performs initialization of the EDAC memory controller |
| 1003 | * instance and related driver-private data associated with the |
| 1004 | * ibm,sdram-4xx-ddr2 memory controller the instance is bound to. |
| 1005 | * |
| 1006 | * Returns 0 if OK; otherwise, < 0 on error. |
| 1007 | */ |
| 1008 | static int __devinit |
| 1009 | ppc4xx_edac_mc_init(struct mem_ctl_info *mci, |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1010 | struct platform_device *op, |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1011 | const dcr_host_t *dcr_host, |
| 1012 | u32 mcopt1) |
| 1013 | { |
| 1014 | int status = 0; |
| 1015 | const u32 memcheck = (mcopt1 & SDRAM_MCOPT1_MCHK_MASK); |
| 1016 | struct ppc4xx_edac_pdata *pdata = NULL; |
Anatolij Gustschin | a26f95f | 2010-06-03 03:17:42 +0200 | [diff] [blame] | 1017 | const struct device_node *np = op->dev.of_node; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1018 | |
Grant Likely | b1608d6 | 2011-05-18 11:19:24 -0600 | [diff] [blame] | 1019 | if (of_match_device(ppc4xx_edac_match, &op->dev) == NULL) |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1020 | return -EINVAL; |
| 1021 | |
| 1022 | /* Initial driver pointers and private data */ |
| 1023 | |
| 1024 | mci->dev = &op->dev; |
| 1025 | |
| 1026 | dev_set_drvdata(mci->dev, mci); |
| 1027 | |
| 1028 | pdata = mci->pvt_info; |
| 1029 | |
| 1030 | pdata->dcr_host = *dcr_host; |
| 1031 | pdata->irqs.sec = NO_IRQ; |
| 1032 | pdata->irqs.ded = NO_IRQ; |
| 1033 | |
| 1034 | /* Initialize controller capabilities and configuration */ |
| 1035 | |
| 1036 | mci->mtype_cap = (MEM_FLAG_DDR | MEM_FLAG_RDDR | |
| 1037 | MEM_FLAG_DDR2 | MEM_FLAG_RDDR2); |
| 1038 | |
| 1039 | mci->edac_ctl_cap = (EDAC_FLAG_NONE | |
| 1040 | EDAC_FLAG_EC | |
| 1041 | EDAC_FLAG_SECDED); |
| 1042 | |
| 1043 | mci->scrub_cap = SCRUB_NONE; |
| 1044 | mci->scrub_mode = SCRUB_NONE; |
| 1045 | |
| 1046 | /* |
| 1047 | * Update the actual capabilites based on the MCOPT1[MCHK] |
| 1048 | * settings. Scrubbing is only useful if reporting is enabled. |
| 1049 | */ |
| 1050 | |
| 1051 | switch (memcheck) { |
| 1052 | case SDRAM_MCOPT1_MCHK_CHK: |
| 1053 | mci->edac_cap = EDAC_FLAG_EC; |
| 1054 | break; |
| 1055 | case SDRAM_MCOPT1_MCHK_CHK_REP: |
| 1056 | mci->edac_cap = (EDAC_FLAG_EC | EDAC_FLAG_SECDED); |
| 1057 | mci->scrub_mode = SCRUB_SW_SRC; |
| 1058 | break; |
| 1059 | default: |
| 1060 | mci->edac_cap = EDAC_FLAG_NONE; |
| 1061 | break; |
| 1062 | } |
| 1063 | |
| 1064 | /* Initialize strings */ |
| 1065 | |
| 1066 | mci->mod_name = PPC4XX_EDAC_MODULE_NAME; |
| 1067 | mci->mod_ver = PPC4XX_EDAC_MODULE_REVISION; |
Mauro Carvalho Chehab | b877763 | 2012-01-31 16:36:08 -0300 | [diff] [blame] | 1068 | mci->ctl_name = ppc4xx_edac_match->compatible, |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1069 | mci->dev_name = np->full_name; |
| 1070 | |
| 1071 | /* Initialize callbacks */ |
| 1072 | |
| 1073 | mci->edac_check = ppc4xx_edac_check; |
| 1074 | mci->ctl_page_to_phys = NULL; |
| 1075 | |
| 1076 | /* Initialize chip select rows */ |
| 1077 | |
| 1078 | status = ppc4xx_edac_init_csrows(mci, mcopt1); |
| 1079 | |
| 1080 | if (status) |
| 1081 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 1082 | "Failed to initialize rows!\n"); |
| 1083 | |
| 1084 | return status; |
| 1085 | } |
| 1086 | |
| 1087 | /** |
| 1088 | * ppc4xx_edac_register_irq - setup and register controller interrupts |
| 1089 | * @op: A pointer to the OpenFirmware device tree node associated |
| 1090 | * with the controller this EDAC instance is bound to. |
| 1091 | * @mci: A pointer to the EDAC memory controller instance |
| 1092 | * associated with the ibm,sdram-4xx-ddr2 controller for which |
| 1093 | * interrupts are being registered. |
| 1094 | * |
| 1095 | * This routine parses the correctable (CE) and uncorrectable error (UE) |
| 1096 | * interrupts from the device tree node and maps and assigns them to |
| 1097 | * the associated EDAC memory controller instance. |
| 1098 | * |
| 1099 | * Returns 0 if OK; otherwise, -ENODEV if the interrupts could not be |
| 1100 | * mapped and assigned. |
| 1101 | */ |
| 1102 | static int __devinit |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1103 | ppc4xx_edac_register_irq(struct platform_device *op, struct mem_ctl_info *mci) |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1104 | { |
| 1105 | int status = 0; |
| 1106 | int ded_irq, sec_irq; |
| 1107 | struct ppc4xx_edac_pdata *pdata = mci->pvt_info; |
Anatolij Gustschin | a26f95f | 2010-06-03 03:17:42 +0200 | [diff] [blame] | 1108 | struct device_node *np = op->dev.of_node; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1109 | |
| 1110 | ded_irq = irq_of_parse_and_map(np, INTMAP_ECCDED_INDEX); |
| 1111 | sec_irq = irq_of_parse_and_map(np, INTMAP_ECCSEC_INDEX); |
| 1112 | |
| 1113 | if (ded_irq == NO_IRQ || sec_irq == NO_IRQ) { |
| 1114 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 1115 | "Unable to map interrupts.\n"); |
| 1116 | status = -ENODEV; |
| 1117 | goto fail; |
| 1118 | } |
| 1119 | |
| 1120 | status = request_irq(ded_irq, |
| 1121 | ppc4xx_edac_isr, |
| 1122 | IRQF_DISABLED, |
| 1123 | "[EDAC] MC ECCDED", |
| 1124 | mci); |
| 1125 | |
| 1126 | if (status < 0) { |
| 1127 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 1128 | "Unable to request irq %d for ECC DED", |
| 1129 | ded_irq); |
| 1130 | status = -ENODEV; |
| 1131 | goto fail1; |
| 1132 | } |
| 1133 | |
| 1134 | status = request_irq(sec_irq, |
| 1135 | ppc4xx_edac_isr, |
| 1136 | IRQF_DISABLED, |
| 1137 | "[EDAC] MC ECCSEC", |
| 1138 | mci); |
| 1139 | |
| 1140 | if (status < 0) { |
| 1141 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 1142 | "Unable to request irq %d for ECC SEC", |
| 1143 | sec_irq); |
| 1144 | status = -ENODEV; |
| 1145 | goto fail2; |
| 1146 | } |
| 1147 | |
| 1148 | ppc4xx_edac_mc_printk(KERN_INFO, mci, "ECCDED irq is %d\n", ded_irq); |
| 1149 | ppc4xx_edac_mc_printk(KERN_INFO, mci, "ECCSEC irq is %d\n", sec_irq); |
| 1150 | |
| 1151 | pdata->irqs.ded = ded_irq; |
| 1152 | pdata->irqs.sec = sec_irq; |
| 1153 | |
| 1154 | return 0; |
| 1155 | |
| 1156 | fail2: |
| 1157 | free_irq(sec_irq, mci); |
| 1158 | |
| 1159 | fail1: |
| 1160 | free_irq(ded_irq, mci); |
| 1161 | |
| 1162 | fail: |
| 1163 | return status; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * ppc4xx_edac_map_dcrs - locate and map controller registers |
| 1168 | * @np: A pointer to the device tree node containing the DCR |
| 1169 | * resources to map. |
| 1170 | * @dcr_host: A pointer to the DCR data to populate with the |
| 1171 | * DCR mapping. |
| 1172 | * |
| 1173 | * This routine attempts to locate in the device tree and map the DCR |
| 1174 | * register resources associated with the controller's indirect DCR |
| 1175 | * address and data windows. |
| 1176 | * |
| 1177 | * Returns 0 if the DCRs were successfully mapped; otherwise, < 0 on |
| 1178 | * error. |
| 1179 | */ |
| 1180 | static int __devinit |
| 1181 | ppc4xx_edac_map_dcrs(const struct device_node *np, dcr_host_t *dcr_host) |
| 1182 | { |
| 1183 | unsigned int dcr_base, dcr_len; |
| 1184 | |
| 1185 | if (np == NULL || dcr_host == NULL) |
| 1186 | return -EINVAL; |
| 1187 | |
| 1188 | /* Get the DCR resource extent and sanity check the values. */ |
| 1189 | |
| 1190 | dcr_base = dcr_resource_start(np, 0); |
| 1191 | dcr_len = dcr_resource_len(np, 0); |
| 1192 | |
| 1193 | if (dcr_base == 0 || dcr_len == 0) { |
| 1194 | ppc4xx_edac_printk(KERN_ERR, |
| 1195 | "Failed to obtain DCR property.\n"); |
| 1196 | return -ENODEV; |
| 1197 | } |
| 1198 | |
| 1199 | if (dcr_len != SDRAM_DCR_RESOURCE_LEN) { |
| 1200 | ppc4xx_edac_printk(KERN_ERR, |
| 1201 | "Unexpected DCR length %d, expected %d.\n", |
| 1202 | dcr_len, SDRAM_DCR_RESOURCE_LEN); |
| 1203 | return -ENODEV; |
| 1204 | } |
| 1205 | |
| 1206 | /* Attempt to map the DCR extent. */ |
| 1207 | |
| 1208 | *dcr_host = dcr_map(np, dcr_base, dcr_len); |
| 1209 | |
| 1210 | if (!DCR_MAP_OK(*dcr_host)) { |
| 1211 | ppc4xx_edac_printk(KERN_INFO, "Failed to map DCRs.\n"); |
| 1212 | return -ENODEV; |
| 1213 | } |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * ppc4xx_edac_probe - check controller and bind driver |
| 1220 | * @op: A pointer to the OpenFirmware device tree node associated |
| 1221 | * with the controller being probed for driver binding. |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1222 | * |
| 1223 | * This routine probes a specific ibm,sdram-4xx-ddr2 controller |
| 1224 | * instance for binding with the driver. |
| 1225 | * |
| 1226 | * Returns 0 if the controller instance was successfully bound to the |
| 1227 | * driver; otherwise, < 0 on error. |
| 1228 | */ |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 1229 | static int __devinit ppc4xx_edac_probe(struct platform_device *op) |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1230 | { |
| 1231 | int status = 0; |
| 1232 | u32 mcopt1, memcheck; |
| 1233 | dcr_host_t dcr_host; |
Anatolij Gustschin | a26f95f | 2010-06-03 03:17:42 +0200 | [diff] [blame] | 1234 | const struct device_node *np = op->dev.of_node; |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1235 | struct mem_ctl_info *mci = NULL; |
| 1236 | static int ppc4xx_edac_instance; |
| 1237 | |
| 1238 | /* |
| 1239 | * At this point, we only support the controller realized on |
| 1240 | * the AMCC PPC 405EX[r]. Reject anything else. |
| 1241 | */ |
| 1242 | |
| 1243 | if (!of_device_is_compatible(np, "ibm,sdram-405ex") && |
| 1244 | !of_device_is_compatible(np, "ibm,sdram-405exr")) { |
| 1245 | ppc4xx_edac_printk(KERN_NOTICE, |
| 1246 | "Only the PPC405EX[r] is supported.\n"); |
| 1247 | return -ENODEV; |
| 1248 | } |
| 1249 | |
| 1250 | /* |
| 1251 | * Next, get the DCR property and attempt to map it so that we |
| 1252 | * can probe the controller. |
| 1253 | */ |
| 1254 | |
| 1255 | status = ppc4xx_edac_map_dcrs(np, &dcr_host); |
| 1256 | |
| 1257 | if (status) |
| 1258 | return status; |
| 1259 | |
| 1260 | /* |
| 1261 | * First determine whether ECC is enabled at all. If not, |
| 1262 | * there is no useful checking or monitoring that can be done |
| 1263 | * for this controller. |
| 1264 | */ |
| 1265 | |
| 1266 | mcopt1 = mfsdram(&dcr_host, SDRAM_MCOPT1); |
| 1267 | memcheck = (mcopt1 & SDRAM_MCOPT1_MCHK_MASK); |
| 1268 | |
| 1269 | if (memcheck == SDRAM_MCOPT1_MCHK_NON) { |
| 1270 | ppc4xx_edac_printk(KERN_INFO, "%s: No ECC memory detected or " |
| 1271 | "ECC is disabled.\n", np->full_name); |
| 1272 | status = -ENODEV; |
| 1273 | goto done; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * At this point, we know ECC is enabled, allocate an EDAC |
| 1278 | * controller instance and perform the appropriate |
| 1279 | * initialization. |
| 1280 | */ |
| 1281 | |
| 1282 | mci = edac_mc_alloc(sizeof(struct ppc4xx_edac_pdata), |
| 1283 | ppc4xx_edac_nr_csrows, |
| 1284 | ppc4xx_edac_nr_chans, |
| 1285 | ppc4xx_edac_instance); |
| 1286 | |
| 1287 | if (mci == NULL) { |
| 1288 | ppc4xx_edac_printk(KERN_ERR, "%s: " |
| 1289 | "Failed to allocate EDAC MC instance!\n", |
| 1290 | np->full_name); |
| 1291 | status = -ENOMEM; |
| 1292 | goto done; |
| 1293 | } |
| 1294 | |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 1295 | status = ppc4xx_edac_mc_init(mci, op, &dcr_host, mcopt1); |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1296 | |
| 1297 | if (status) { |
| 1298 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 1299 | "Failed to initialize instance!\n"); |
| 1300 | goto fail; |
| 1301 | } |
| 1302 | |
| 1303 | /* |
| 1304 | * We have a valid, initialized EDAC instance bound to the |
| 1305 | * controller. Attempt to register it with the EDAC subsystem |
| 1306 | * and, if necessary, register interrupts. |
| 1307 | */ |
| 1308 | |
| 1309 | if (edac_mc_add_mc(mci)) { |
| 1310 | ppc4xx_edac_mc_printk(KERN_ERR, mci, |
| 1311 | "Failed to add instance!\n"); |
| 1312 | status = -ENODEV; |
| 1313 | goto fail; |
| 1314 | } |
| 1315 | |
| 1316 | if (edac_op_state == EDAC_OPSTATE_INT) { |
| 1317 | status = ppc4xx_edac_register_irq(op, mci); |
| 1318 | |
| 1319 | if (status) |
| 1320 | goto fail1; |
| 1321 | } |
| 1322 | |
| 1323 | ppc4xx_edac_instance++; |
| 1324 | |
| 1325 | return 0; |
| 1326 | |
| 1327 | fail1: |
| 1328 | edac_mc_del_mc(mci->dev); |
| 1329 | |
| 1330 | fail: |
| 1331 | edac_mc_free(mci); |
| 1332 | |
| 1333 | done: |
| 1334 | return status; |
| 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * ppc4xx_edac_remove - unbind driver from controller |
| 1339 | * @op: A pointer to the OpenFirmware device tree node associated |
| 1340 | * with the controller this EDAC instance is to be unbound/removed |
| 1341 | * from. |
| 1342 | * |
| 1343 | * This routine unbinds the EDAC memory controller instance associated |
| 1344 | * with the specified ibm,sdram-4xx-ddr2 controller described by the |
| 1345 | * OpenFirmware device tree node passed as a parameter. |
| 1346 | * |
| 1347 | * Unconditionally returns 0. |
| 1348 | */ |
| 1349 | static int |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 1350 | ppc4xx_edac_remove(struct platform_device *op) |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1351 | { |
| 1352 | struct mem_ctl_info *mci = dev_get_drvdata(&op->dev); |
| 1353 | struct ppc4xx_edac_pdata *pdata = mci->pvt_info; |
| 1354 | |
| 1355 | if (edac_op_state == EDAC_OPSTATE_INT) { |
| 1356 | free_irq(pdata->irqs.sec, mci); |
| 1357 | free_irq(pdata->irqs.ded, mci); |
| 1358 | } |
| 1359 | |
| 1360 | dcr_unmap(pdata->dcr_host, SDRAM_DCR_RESOURCE_LEN); |
| 1361 | |
| 1362 | edac_mc_del_mc(mci->dev); |
| 1363 | edac_mc_free(mci); |
| 1364 | |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * ppc4xx_edac_opstate_init - initialize EDAC reporting method |
| 1370 | * |
| 1371 | * This routine ensures that the EDAC memory controller reporting |
| 1372 | * method is mapped to a sane value as the EDAC core defines the value |
| 1373 | * to EDAC_OPSTATE_INVAL by default. We don't call the global |
| 1374 | * opstate_init as that defaults to polling and we want interrupt as |
| 1375 | * the default. |
| 1376 | */ |
| 1377 | static inline void __init |
| 1378 | ppc4xx_edac_opstate_init(void) |
| 1379 | { |
| 1380 | switch (edac_op_state) { |
| 1381 | case EDAC_OPSTATE_POLL: |
| 1382 | case EDAC_OPSTATE_INT: |
| 1383 | break; |
| 1384 | default: |
| 1385 | edac_op_state = EDAC_OPSTATE_INT; |
| 1386 | break; |
| 1387 | } |
| 1388 | |
| 1389 | ppc4xx_edac_printk(KERN_INFO, "Reporting type: %s\n", |
| 1390 | ((edac_op_state == EDAC_OPSTATE_POLL) ? |
| 1391 | EDAC_OPSTATE_POLL_STR : |
| 1392 | ((edac_op_state == EDAC_OPSTATE_INT) ? |
| 1393 | EDAC_OPSTATE_INT_STR : |
| 1394 | EDAC_OPSTATE_UNKNOWN_STR))); |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * ppc4xx_edac_init - driver/module insertion entry point |
| 1399 | * |
| 1400 | * This routine is the driver/module insertion entry point. It |
| 1401 | * initializes the EDAC memory controller reporting state and |
| 1402 | * registers the driver as an OpenFirmware device tree platform |
| 1403 | * driver. |
| 1404 | */ |
| 1405 | static int __init |
| 1406 | ppc4xx_edac_init(void) |
| 1407 | { |
| 1408 | ppc4xx_edac_printk(KERN_INFO, PPC4XX_EDAC_MODULE_REVISION "\n"); |
| 1409 | |
| 1410 | ppc4xx_edac_opstate_init(); |
| 1411 | |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 1412 | return platform_driver_register(&ppc4xx_edac_driver); |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /** |
| 1416 | * ppc4xx_edac_exit - driver/module removal entry point |
| 1417 | * |
| 1418 | * This routine is the driver/module removal entry point. It |
| 1419 | * unregisters the driver as an OpenFirmware device tree platform |
| 1420 | * driver. |
| 1421 | */ |
| 1422 | static void __exit |
| 1423 | ppc4xx_edac_exit(void) |
| 1424 | { |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 1425 | platform_driver_unregister(&ppc4xx_edac_driver); |
Grant Erickson | dba7a77 | 2009-04-02 16:58:45 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | module_init(ppc4xx_edac_init); |
| 1429 | module_exit(ppc4xx_edac_exit); |
| 1430 | |
| 1431 | MODULE_LICENSE("GPL v2"); |
| 1432 | MODULE_AUTHOR("Grant Erickson <gerickson@nuovations.com>"); |
| 1433 | MODULE_DESCRIPTION("EDAC MC Driver for the PPC4xx IBM DDR2 Memory Controller"); |
| 1434 | module_param(edac_op_state, int, 0444); |
| 1435 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting State: " |
| 1436 | "0=" EDAC_OPSTATE_POLL_STR ", 2=" EDAC_OPSTATE_INT_STR); |