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