1/* 2 * Generic EDAC defs 3 * 4 * Author: Dave Jiang <djiang@mvista.com> 5 * 6 * 2006-2008 (c) MontaVista Software, Inc. This file is licensed under 7 * the terms of the GNU General Public License version 2. This program 8 * is licensed "as is" without any warranty of any kind, whether express 9 * or implied. 10 * 11 */ 12#ifndef _LINUX_EDAC_H_ 13#define _LINUX_EDAC_H_ 14 15#include <linux/atomic.h> 16#include <linux/device.h> 17#include <linux/completion.h> 18#include <linux/workqueue.h> 19#include <linux/debugfs.h> 20#include <linux/numa.h> 21 22struct device; 23 24#define EDAC_OPSTATE_INVAL -1 25#define EDAC_OPSTATE_POLL 0 26#define EDAC_OPSTATE_NMI 1 27#define EDAC_OPSTATE_INT 2 28 29extern int edac_op_state; 30extern int edac_err_assert; 31extern atomic_t edac_handlers; 32extern struct bus_type edac_subsys; 33 34extern int edac_handler_set(void); 35extern void edac_atomic_assert_error(void); 36extern struct bus_type *edac_get_sysfs_subsys(void); 37extern void edac_put_sysfs_subsys(void); 38 39enum { 40 EDAC_REPORTING_ENABLED, 41 EDAC_REPORTING_DISABLED, 42 EDAC_REPORTING_FORCE 43}; 44 45extern int edac_report_status; 46#ifdef CONFIG_EDAC 47static inline int get_edac_report_status(void) 48{ 49 return edac_report_status; 50} 51 52static inline void set_edac_report_status(int new) 53{ 54 edac_report_status = new; 55} 56#else 57static inline int get_edac_report_status(void) 58{ 59 return EDAC_REPORTING_DISABLED; 60} 61 62static inline void set_edac_report_status(int new) 63{ 64} 65#endif 66 67static inline void opstate_init(void) 68{ 69 switch (edac_op_state) { 70 case EDAC_OPSTATE_POLL: 71 case EDAC_OPSTATE_NMI: 72 break; 73 default: 74 edac_op_state = EDAC_OPSTATE_POLL; 75 } 76 return; 77} 78 79/* Max length of a DIMM label*/ 80#define EDAC_MC_LABEL_LEN 31 81 82/* Maximum size of the location string */ 83#define LOCATION_SIZE 256 84 85/* Defines the maximum number of labels that can be reported */ 86#define EDAC_MAX_LABELS 8 87 88/* String used to join two or more labels */ 89#define OTHER_LABEL " or " 90 91/** 92 * enum dev_type - describe the type of memory DRAM chips used at the stick 93 * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it 94 * @DEV_X1: 1 bit for data 95 * @DEV_X2: 2 bits for data 96 * @DEV_X4: 4 bits for data 97 * @DEV_X8: 8 bits for data 98 * @DEV_X16: 16 bits for data 99 * @DEV_X32: 32 bits for data 100 * @DEV_X64: 64 bits for data 101 * 102 * Typical values are x4 and x8. 103 */ 104enum dev_type { 105 DEV_UNKNOWN = 0, 106 DEV_X1, 107 DEV_X2, 108 DEV_X4, 109 DEV_X8, 110 DEV_X16, 111 DEV_X32, /* Do these parts exist? */ 112 DEV_X64 /* Do these parts exist? */ 113}; 114 115#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN) 116#define DEV_FLAG_X1 BIT(DEV_X1) 117#define DEV_FLAG_X2 BIT(DEV_X2) 118#define DEV_FLAG_X4 BIT(DEV_X4) 119#define DEV_FLAG_X8 BIT(DEV_X8) 120#define DEV_FLAG_X16 BIT(DEV_X16) 121#define DEV_FLAG_X32 BIT(DEV_X32) 122#define DEV_FLAG_X64 BIT(DEV_X64) 123 124/** 125 * enum hw_event_mc_err_type - type of the detected error 126 * 127 * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC 128 * corrected error was detected 129 * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that 130 * can't be corrected by ECC, but it is not 131 * fatal (maybe it is on an unused memory area, 132 * or the memory controller could recover from 133 * it for example, by re-trying the operation). 134 * @HW_EVENT_ERR_DEFERRED: Deferred Error - Indicates an uncorrectable 135 * error whose handling is not urgent. This could 136 * be due to hardware data poisoning where the 137 * system can continue operation until the poisoned 138 * data is consumed. Preemptive measures may also 139 * be taken, e.g. offlining pages, etc. 140 * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not 141 * be recovered. 142 */ 143enum hw_event_mc_err_type { 144 HW_EVENT_ERR_CORRECTED, 145 HW_EVENT_ERR_UNCORRECTED, 146 HW_EVENT_ERR_DEFERRED, 147 HW_EVENT_ERR_FATAL, 148 HW_EVENT_ERR_INFO, 149}; 150 151static inline char *mc_event_error_type(const unsigned int err_type) 152{ 153 switch (err_type) { 154 case HW_EVENT_ERR_CORRECTED: 155 return "Corrected"; 156 case HW_EVENT_ERR_UNCORRECTED: 157 return "Uncorrected"; 158 case HW_EVENT_ERR_DEFERRED: 159 return "Deferred"; 160 case HW_EVENT_ERR_FATAL: 161 return "Fatal"; 162 default: 163 case HW_EVENT_ERR_INFO: 164 return "Info"; 165 } 166} 167 168/** 169 * enum mem_type - memory types. For a more detailed reference, please see 170 * http://en.wikipedia.org/wiki/DRAM 171 * 172 * @MEM_EMPTY Empty csrow 173 * @MEM_RESERVED: Reserved csrow type 174 * @MEM_UNKNOWN: Unknown csrow type 175 * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995. 176 * @MEM_EDO: EDO - Extended data out, used on systems up to 1998. 177 * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant. 178 * @MEM_SDR: SDR - Single data rate SDRAM 179 * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory 180 * They use 3 pins for chip select: Pins 0 and 2 are 181 * for rank 0; pins 1 and 3 are for rank 1, if the memory 182 * is dual-rank. 183 * @MEM_RDR: Registered SDR SDRAM 184 * @MEM_DDR: Double data rate SDRAM 185 * http://en.wikipedia.org/wiki/DDR_SDRAM 186 * @MEM_RDDR: Registered Double data rate SDRAM 187 * This is a variant of the DDR memories. 188 * A registered memory has a buffer inside it, hiding 189 * part of the memory details to the memory controller. 190 * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers. 191 * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F. 192 * Those memories are labed as "PC2-" instead of "PC" to 193 * differenciate from DDR. 194 * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205 195 * and JESD206. 196 * Those memories are accessed per DIMM slot, and not by 197 * a chip select signal. 198 * @MEM_RDDR2: Registered DDR2 RAM 199 * This is a variant of the DDR2 memories. 200 * @MEM_XDR: Rambus XDR 201 * It is an evolution of the original RAMBUS memories, 202 * created to compete with DDR2. Weren't used on any 203 * x86 arch, but cell_edac PPC memory controller uses it. 204 * @MEM_DDR3: DDR3 RAM 205 * @MEM_RDDR3: Registered DDR3 RAM 206 * This is a variant of the DDR3 memories. 207 * @MEM_LRDDR3: Load-Reduced DDR3 memory. 208 * @MEM_DDR4: Unbuffered DDR4 RAM 209 * @MEM_RDDR4: Registered DDR4 RAM 210 * This is a variant of the DDR4 memories. 211 * @MEM_LRDDR4: Load-Reduced DDR4 memory. 212 * @MEM_NVDIMM: Non-volatile RAM 213 */ 214enum mem_type { 215 MEM_EMPTY = 0, 216 MEM_RESERVED, 217 MEM_UNKNOWN, 218 MEM_FPM, 219 MEM_EDO, 220 MEM_BEDO, 221 MEM_SDR, 222 MEM_RDR, 223 MEM_DDR, 224 MEM_RDDR, 225 MEM_RMBS, 226 MEM_DDR2, 227 MEM_FB_DDR2, 228 MEM_RDDR2, 229 MEM_XDR, 230 MEM_DDR3, 231 MEM_RDDR3, 232 MEM_LRDDR3, 233 MEM_DDR4, 234 MEM_RDDR4, 235 MEM_LRDDR4, 236 MEM_NVDIMM, 237}; 238 239#define MEM_FLAG_EMPTY BIT(MEM_EMPTY) 240#define MEM_FLAG_RESERVED BIT(MEM_RESERVED) 241#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN) 242#define MEM_FLAG_FPM BIT(MEM_FPM) 243#define MEM_FLAG_EDO BIT(MEM_EDO) 244#define MEM_FLAG_BEDO BIT(MEM_BEDO) 245#define MEM_FLAG_SDR BIT(MEM_SDR) 246#define MEM_FLAG_RDR BIT(MEM_RDR) 247#define MEM_FLAG_DDR BIT(MEM_DDR) 248#define MEM_FLAG_RDDR BIT(MEM_RDDR) 249#define MEM_FLAG_RMBS BIT(MEM_RMBS) 250#define MEM_FLAG_DDR2 BIT(MEM_DDR2) 251#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2) 252#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2) 253#define MEM_FLAG_XDR BIT(MEM_XDR) 254#define MEM_FLAG_DDR3 BIT(MEM_DDR3) 255#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3) 256#define MEM_FLAG_DDR4 BIT(MEM_DDR4) 257#define MEM_FLAG_RDDR4 BIT(MEM_RDDR4) 258#define MEM_FLAG_LRDDR4 BIT(MEM_LRDDR4) 259#define MEM_FLAG_NVDIMM BIT(MEM_NVDIMM) 260 261/** 262 * enum edac-type - Error Detection and Correction capabilities and mode 263 * @EDAC_UNKNOWN: Unknown if ECC is available 264 * @EDAC_NONE: Doesn't support ECC 265 * @EDAC_RESERVED: Reserved ECC type 266 * @EDAC_PARITY: Detects parity errors 267 * @EDAC_EC: Error Checking - no correction 268 * @EDAC_SECDED: Single bit error correction, Double detection 269 * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist? 270 * @EDAC_S4ECD4ED: Chipkill x4 devices 271 * @EDAC_S8ECD8ED: Chipkill x8 devices 272 * @EDAC_S16ECD16ED: Chipkill x16 devices 273 */ 274enum edac_type { 275 EDAC_UNKNOWN = 0, 276 EDAC_NONE, 277 EDAC_RESERVED, 278 EDAC_PARITY, 279 EDAC_EC, 280 EDAC_SECDED, 281 EDAC_S2ECD2ED, 282 EDAC_S4ECD4ED, 283 EDAC_S8ECD8ED, 284 EDAC_S16ECD16ED, 285}; 286 287#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN) 288#define EDAC_FLAG_NONE BIT(EDAC_NONE) 289#define EDAC_FLAG_PARITY BIT(EDAC_PARITY) 290#define EDAC_FLAG_EC BIT(EDAC_EC) 291#define EDAC_FLAG_SECDED BIT(EDAC_SECDED) 292#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED) 293#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED) 294#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED) 295#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED) 296 297/** 298 * enum scrub_type - scrubbing capabilities 299 * @SCRUB_UNKNOWN Unknown if scrubber is available 300 * @SCRUB_NONE: No scrubber 301 * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing 302 * @SCRUB_SW_SRC: Software scrub only errors 303 * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error 304 * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable 305 * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing 306 * @SCRUB_HW_SRC: Hardware scrub only errors 307 * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error 308 * SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable 309 */ 310enum scrub_type { 311 SCRUB_UNKNOWN = 0, 312 SCRUB_NONE, 313 SCRUB_SW_PROG, 314 SCRUB_SW_SRC, 315 SCRUB_SW_PROG_SRC, 316 SCRUB_SW_TUNABLE, 317 SCRUB_HW_PROG, 318 SCRUB_HW_SRC, 319 SCRUB_HW_PROG_SRC, 320 SCRUB_HW_TUNABLE 321}; 322 323#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG) 324#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC) 325#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC) 326#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE) 327#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG) 328#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC) 329#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC) 330#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE) 331 332/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */ 333 334/* EDAC internal operation states */ 335#define OP_ALLOC 0x100 336#define OP_RUNNING_POLL 0x201 337#define OP_RUNNING_INTERRUPT 0x202 338#define OP_RUNNING_POLL_INTR 0x203 339#define OP_OFFLINE 0x300 340 341/* 342 * Concepts used at the EDAC subsystem 343 * 344 * There are several things to be aware of that aren't at all obvious: 345 * 346 * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc.. 347 * 348 * These are some of the many terms that are thrown about that don't always 349 * mean what people think they mean (Inconceivable!). In the interest of 350 * creating a common ground for discussion, terms and their definitions 351 * will be established. 352 * 353 * Memory devices: The individual DRAM chips on a memory stick. These 354 * devices commonly output 4 and 8 bits each (x4, x8). 355 * Grouping several of these in parallel provides the 356 * number of bits that the memory controller expects: 357 * typically 72 bits, in order to provide 64 bits + 358 * 8 bits of ECC data. 359 * 360 * Memory Stick: A printed circuit board that aggregates multiple 361 * memory devices in parallel. In general, this is the 362 * Field Replaceable Unit (FRU) which gets replaced, in 363 * the case of excessive errors. Most often it is also 364 * called DIMM (Dual Inline Memory Module). 365 * 366 * Memory Socket: A physical connector on the motherboard that accepts 367 * a single memory stick. Also called as "slot" on several 368 * datasheets. 369 * 370 * Channel: A memory controller channel, responsible to communicate 371 * with a group of DIMMs. Each channel has its own 372 * independent control (command) and data bus, and can 373 * be used independently or grouped with other channels. 374 * 375 * Branch: It is typically the highest hierarchy on a 376 * Fully-Buffered DIMM memory controller. 377 * Typically, it contains two channels. 378 * Two channels at the same branch can be used in single 379 * mode or in lockstep mode. 380 * When lockstep is enabled, the cacheline is doubled, 381 * but it generally brings some performance penalty. 382 * Also, it is generally not possible to point to just one 383 * memory stick when an error occurs, as the error 384 * correction code is calculated using two DIMMs instead 385 * of one. Due to that, it is capable of correcting more 386 * errors than on single mode. 387 * 388 * Single-channel: The data accessed by the memory controller is contained 389 * into one dimm only. E. g. if the data is 64 bits-wide, 390 * the data flows to the CPU using one 64 bits parallel 391 * access. 392 * Typically used with SDR, DDR, DDR2 and DDR3 memories. 393 * FB-DIMM and RAMBUS use a different concept for channel, 394 * so this concept doesn't apply there. 395 * 396 * Double-channel: The data size accessed by the memory controller is 397 * interlaced into two dimms, accessed at the same time. 398 * E. g. if the DIMM is 64 bits-wide (72 bits with ECC), 399 * the data flows to the CPU using a 128 bits parallel 400 * access. 401 * 402 * Chip-select row: This is the name of the DRAM signal used to select the 403 * DRAM ranks to be accessed. Common chip-select rows for 404 * single channel are 64 bits, for dual channel 128 bits. 405 * It may not be visible by the memory controller, as some 406 * DIMM types have a memory buffer that can hide direct 407 * access to it from the Memory Controller. 408 * 409 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory. 410 * Motherboards commonly drive two chip-select pins to 411 * a memory stick. A single-ranked stick, will occupy 412 * only one of those rows. The other will be unused. 413 * 414 * Double-Ranked stick: A double-ranked stick has two chip-select rows which 415 * access different sets of memory devices. The two 416 * rows cannot be accessed concurrently. 417 * 418 * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick. 419 * A double-sided stick has two chip-select rows which 420 * access different sets of memory devices. The two 421 * rows cannot be accessed concurrently. "Double-sided" 422 * is irrespective of the memory devices being mounted 423 * on both sides of the memory stick. 424 * 425 * Socket set: All of the memory sticks that are required for 426 * a single memory access or all of the memory sticks 427 * spanned by a chip-select row. A single socket set 428 * has two chip-select rows and if double-sided sticks 429 * are used these will occupy those chip-select rows. 430 * 431 * Bank: This term is avoided because it is unclear when 432 * needing to distinguish between chip-select rows and 433 * socket sets. 434 * 435 * Controller pages: 436 * 437 * Physical pages: 438 * 439 * Virtual pages: 440 * 441 * 442 * STRUCTURE ORGANIZATION AND CHOICES 443 * 444 * 445 * 446 * PS - I enjoyed writing all that about as much as you enjoyed reading it. 447 */ 448 449/** 450 * enum edac_mc_layer - memory controller hierarchy layer 451 * 452 * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch" 453 * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel" 454 * @EDAC_MC_LAYER_SLOT: memory layer is named "slot" 455 * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select" 456 * @EDAC_MC_LAYER_ALL_MEM: memory layout is unknown. All memory is mapped 457 * as a single memory area. This is used when 458 * retrieving errors from a firmware driven driver. 459 * 460 * This enum is used by the drivers to tell edac_mc_sysfs what name should 461 * be used when describing a memory stick location. 462 */ 463enum edac_mc_layer_type { 464 EDAC_MC_LAYER_BRANCH, 465 EDAC_MC_LAYER_CHANNEL, 466 EDAC_MC_LAYER_SLOT, 467 EDAC_MC_LAYER_CHIP_SELECT, 468 EDAC_MC_LAYER_ALL_MEM, 469}; 470 471/** 472 * struct edac_mc_layer - describes the memory controller hierarchy 473 * @layer: layer type 474 * @size: number of components per layer. For example, 475 * if the channel layer has two channels, size = 2 476 * @is_virt_csrow: This layer is part of the "csrow" when old API 477 * compatibility mode is enabled. Otherwise, it is 478 * a channel 479 */ 480struct edac_mc_layer { 481 enum edac_mc_layer_type type; 482 unsigned size; 483 bool is_virt_csrow; 484}; 485 486/* 487 * Maximum number of layers used by the memory controller to uniquely 488 * identify a single memory stick. 489 * NOTE: Changing this constant requires not only to change the constant 490 * below, but also to change the existing code at the core, as there are 491 * some code there that are optimized for 3 layers. 492 */ 493#define EDAC_MAX_LAYERS 3 494 495/** 496 * EDAC_DIMM_OFF - Macro responsible to get a pointer offset inside a pointer array 497 * for the element given by [layer0,layer1,layer2] position 498 * 499 * @layers: a struct edac_mc_layer array, describing how many elements 500 * were allocated for each layer 501 * @n_layers: Number of layers at the @layers array 502 * @layer0: layer0 position 503 * @layer1: layer1 position. Unused if n_layers < 2 504 * @layer2: layer2 position. Unused if n_layers < 3 505 * 506 * For 1 layer, this macro returns &var[layer0] - &var 507 * For 2 layers, this macro is similar to allocate a bi-dimensional array 508 * and to return "&var[layer0][layer1] - &var" 509 * For 3 layers, this macro is similar to allocate a tri-dimensional array 510 * and to return "&var[layer0][layer1][layer2] - &var" 511 * 512 * A loop could be used here to make it more generic, but, as we only have 513 * 3 layers, this is a little faster. 514 * By design, layers can never be 0 or more than 3. If that ever happens, 515 * a NULL is returned, causing an OOPS during the memory allocation routine, 516 * with would point to the developer that he's doing something wrong. 517 */ 518#define EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2) ({ \ 519 int __i; \ 520 if ((nlayers) == 1) \ 521 __i = layer0; \ 522 else if ((nlayers) == 2) \ 523 __i = (layer1) + ((layers[1]).size * (layer0)); \ 524 else if ((nlayers) == 3) \ 525 __i = (layer2) + ((layers[2]).size * ((layer1) + \ 526 ((layers[1]).size * (layer0)))); \ 527 else \ 528 __i = -EINVAL; \ 529 __i; \ 530}) 531 532/** 533 * EDAC_DIMM_PTR - Macro responsible to get a pointer inside a pointer array 534 * for the element given by [layer0,layer1,layer2] position 535 * 536 * @layers: a struct edac_mc_layer array, describing how many elements 537 * were allocated for each layer 538 * @var: name of the var where we want to get the pointer 539 * (like mci->dimms) 540 * @n_layers: Number of layers at the @layers array 541 * @layer0: layer0 position 542 * @layer1: layer1 position. Unused if n_layers < 2 543 * @layer2: layer2 position. Unused if n_layers < 3 544 * 545 * For 1 layer, this macro returns &var[layer0] 546 * For 2 layers, this macro is similar to allocate a bi-dimensional array 547 * and to return "&var[layer0][layer1]" 548 * For 3 layers, this macro is similar to allocate a tri-dimensional array 549 * and to return "&var[layer0][layer1][layer2]" 550 */ 551#define EDAC_DIMM_PTR(layers, var, nlayers, layer0, layer1, layer2) ({ \ 552 typeof(*var) __p; \ 553 int ___i = EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2); \ 554 if (___i < 0) \ 555 __p = NULL; \ 556 else \ 557 __p = (var)[___i]; \ 558 __p; \ 559}) 560 561struct dimm_info { 562 struct device dev; 563 564 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */ 565 566 /* Memory location data */ 567 unsigned location[EDAC_MAX_LAYERS]; 568 569 struct mem_ctl_info *mci; /* the parent */ 570 571 u32 grain; /* granularity of reported error in bytes */ 572 enum dev_type dtype; /* memory device type */ 573 enum mem_type mtype; /* memory dimm type */ 574 enum edac_type edac_mode; /* EDAC mode for this dimm */ 575 576 u32 nr_pages; /* number of pages on this dimm */ 577 578 unsigned csrow, cschannel; /* Points to the old API data */ 579}; 580 581/** 582 * struct rank_info - contains the information for one DIMM rank 583 * 584 * @chan_idx: channel number where the rank is (typically, 0 or 1) 585 * @ce_count: number of correctable errors for this rank 586 * @csrow: A pointer to the chip select row structure (the parent 587 * structure). The location of the rank is given by 588 * the (csrow->csrow_idx, chan_idx) vector. 589 * @dimm: A pointer to the DIMM structure, where the DIMM label 590 * information is stored. 591 * 592 * FIXME: Currently, the EDAC core model will assume one DIMM per rank. 593 * This is a bad assumption, but it makes this patch easier. Later 594 * patches in this series will fix this issue. 595 */ 596struct rank_info { 597 int chan_idx; 598 struct csrow_info *csrow; 599 struct dimm_info *dimm; 600 601 u32 ce_count; /* Correctable Errors for this csrow */ 602}; 603 604struct csrow_info { 605 struct device dev; 606 607 /* Used only by edac_mc_find_csrow_by_page() */ 608 unsigned long first_page; /* first page number in csrow */ 609 unsigned long last_page; /* last page number in csrow */ 610 unsigned long page_mask; /* used for interleaving - 611 * 0UL for non intlv */ 612 613 int csrow_idx; /* the chip-select row */ 614 615 u32 ue_count; /* Uncorrectable Errors for this csrow */ 616 u32 ce_count; /* Correctable Errors for this csrow */ 617 618 struct mem_ctl_info *mci; /* the parent */ 619 620 /* channel information for this csrow */ 621 u32 nr_channels; 622 struct rank_info **channels; 623}; 624 625/* 626 * struct errcount_attribute - used to store the several error counts 627 */ 628struct errcount_attribute_data { 629 int n_layers; 630 int pos[EDAC_MAX_LAYERS]; 631 int layer0, layer1, layer2; 632}; 633 634/** 635 * edac_raw_error_desc - Raw error report structure 636 * @grain: minimum granularity for an error report, in bytes 637 * @error_count: number of errors of the same type 638 * @top_layer: top layer of the error (layer[0]) 639 * @mid_layer: middle layer of the error (layer[1]) 640 * @low_layer: low layer of the error (layer[2]) 641 * @page_frame_number: page where the error happened 642 * @offset_in_page: page offset 643 * @syndrome: syndrome of the error (or 0 if unknown or if 644 * the syndrome is not applicable) 645 * @msg: error message 646 * @location: location of the error 647 * @label: label of the affected DIMM(s) 648 * @other_detail: other driver-specific detail about the error 649 * @enable_per_layer_report: if false, the error affects all layers 650 * (typically, a memory controller error) 651 */ 652struct edac_raw_error_desc { 653 /* 654 * NOTE: everything before grain won't be cleaned by 655 * edac_raw_error_desc_clean() 656 */ 657 char location[LOCATION_SIZE]; 658 char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS]; 659 long grain; 660 661 /* the vars below and grain will be cleaned on every new error report */ 662 u16 error_count; 663 int top_layer; 664 int mid_layer; 665 int low_layer; 666 unsigned long page_frame_number; 667 unsigned long offset_in_page; 668 unsigned long syndrome; 669 const char *msg; 670 const char *other_detail; 671 bool enable_per_layer_report; 672}; 673 674/* MEMORY controller information structure 675 */ 676struct mem_ctl_info { 677 struct device dev; 678 struct bus_type *bus; 679 680 struct list_head link; /* for global list of mem_ctl_info structs */ 681 682 struct module *owner; /* Module owner of this control struct */ 683 684 unsigned long mtype_cap; /* memory types supported by mc */ 685 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */ 686 unsigned long edac_cap; /* configuration capabilities - this is 687 * closely related to edac_ctl_cap. The 688 * difference is that the controller may be 689 * capable of s4ecd4ed which would be listed 690 * in edac_ctl_cap, but if channels aren't 691 * capable of s4ecd4ed then the edac_cap would 692 * not have that capability. 693 */ 694 unsigned long scrub_cap; /* chipset scrub capabilities */ 695 enum scrub_type scrub_mode; /* current scrub mode */ 696 697 /* Translates sdram memory scrub rate given in bytes/sec to the 698 internal representation and configures whatever else needs 699 to be configured. 700 */ 701 int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw); 702 703 /* Get the current sdram memory scrub rate from the internal 704 representation and converts it to the closest matching 705 bandwidth in bytes/sec. 706 */ 707 int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci); 708 709 710 /* pointer to edac checking routine */ 711 void (*edac_check) (struct mem_ctl_info * mci); 712 713 /* 714 * Remaps memory pages: controller pages to physical pages. 715 * For most MC's, this will be NULL. 716 */ 717 /* FIXME - why not send the phys page to begin with? */ 718 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci, 719 unsigned long page); 720 int mc_idx; 721 struct csrow_info **csrows; 722 unsigned nr_csrows, num_cschannel; 723 724 /* 725 * Memory Controller hierarchy 726 * 727 * There are basically two types of memory controller: the ones that 728 * sees memory sticks ("dimms"), and the ones that sees memory ranks. 729 * All old memory controllers enumerate memories per rank, but most 730 * of the recent drivers enumerate memories per DIMM, instead. 731 * When the memory controller is per rank, csbased is true. 732 */ 733 unsigned n_layers; 734 struct edac_mc_layer *layers; 735 bool csbased; 736 737 /* 738 * DIMM info. Will eventually remove the entire csrows_info some day 739 */ 740 unsigned tot_dimms; 741 struct dimm_info **dimms; 742 743 /* 744 * FIXME - what about controllers on other busses? - IDs must be 745 * unique. dev pointer should be sufficiently unique, but 746 * BUS:SLOT.FUNC numbers may not be unique. 747 */ 748 struct device *pdev; 749 const char *mod_name; 750 const char *mod_ver; 751 const char *ctl_name; 752 const char *dev_name; 753 void *pvt_info; 754 unsigned long start_time; /* mci load start time (in jiffies) */ 755 756 /* 757 * drivers shouldn't access those fields directly, as the core 758 * already handles that. 759 */ 760 u32 ce_noinfo_count, ue_noinfo_count; 761 u32 ue_mc, ce_mc; 762 u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS]; 763 764 struct completion complete; 765 766 /* Additional top controller level attributes, but specified 767 * by the low level driver. 768 * 769 * Set by the low level driver to provide attributes at the 770 * controller level. 771 * An array of structures, NULL terminated 772 * 773 * If attributes are desired, then set to array of attributes 774 * If no attributes are desired, leave NULL 775 */ 776 const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes; 777 778 /* work struct for this MC */ 779 struct delayed_work work; 780 781 /* 782 * Used to report an error - by being at the global struct 783 * makes the memory allocated by the EDAC core 784 */ 785 struct edac_raw_error_desc error_desc; 786 787 /* the internal state of this controller instance */ 788 int op_state; 789 790#ifdef CONFIG_EDAC_DEBUG 791 struct dentry *debugfs; 792 u8 fake_inject_layer[EDAC_MAX_LAYERS]; 793 u32 fake_inject_ue; 794 u16 fake_inject_count; 795#endif 796}; 797 798#endif 799