blob: 0fec0f26469bf34d7b3ec1a8c040866171f3d606 [file] [log] [blame]
Dave Jiangc0d12172007-07-19 01:49:46 -07001/*
2 * Generic EDAC defs
3 *
4 * Author: Dave Jiang <djiang@mvista.com>
5 *
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -07006 * 2006-2008 (c) MontaVista Software, Inc. This file is licensed under
Dave Jiangc0d12172007-07-19 01:49:46 -07007 * 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 Sharma600634972011-07-26 16:09:06 -070015#include <linux/atomic.h>
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -030016#include <linux/device.h>
Paul Gortmaker313162d2012-01-30 11:46:54 -050017#include <linux/completion.h>
18#include <linux/workqueue.h>
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -030019#include <linux/debugfs.h>
Paul Gortmaker313162d2012-01-30 11:46:54 -050020
Mauro Carvalho Chehab0b892c72016-10-29 09:56:00 -020021#define EDAC_DEVICE_NAME_LEN 31
22
Paul Gortmaker313162d2012-01-30 11:46:54 -050023struct device;
Dave Jiangc0d12172007-07-19 01:49:46 -070024
25#define EDAC_OPSTATE_INVAL -1
26#define EDAC_OPSTATE_POLL 0
27#define EDAC_OPSTATE_NMI 1
28#define EDAC_OPSTATE_INT 2
29
30extern int edac_op_state;
Dave Jiang66ee2f92007-07-19 01:49:54 -070031extern int edac_err_assert;
Dave Jiangc0d12172007-07-19 01:49:46 -070032extern atomic_t edac_handlers;
Dave Jiangc0d12172007-07-19 01:49:46 -070033
34extern int edac_handler_set(void);
35extern void edac_atomic_assert_error(void);
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080036extern struct bus_type *edac_get_sysfs_subsys(void);
Dave Jiangc0d12172007-07-19 01:49:46 -070037
Chen, Gongc700f012013-12-06 01:17:08 -050038enum {
39 EDAC_REPORTING_ENABLED,
40 EDAC_REPORTING_DISABLED,
41 EDAC_REPORTING_FORCE
42};
43
44extern int edac_report_status;
45#ifdef CONFIG_EDAC
46static inline int get_edac_report_status(void)
47{
48 return edac_report_status;
49}
50
51static inline void set_edac_report_status(int new)
52{
53 edac_report_status = new;
54}
55#else
56static inline int get_edac_report_status(void)
57{
58 return EDAC_REPORTING_DISABLED;
59}
60
61static inline void set_edac_report_status(int new)
62{
63}
64#endif
65
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -070066static inline void opstate_init(void)
67{
68 switch (edac_op_state) {
69 case EDAC_OPSTATE_POLL:
70 case EDAC_OPSTATE_NMI:
71 break;
72 default:
73 edac_op_state = EDAC_OPSTATE_POLL;
74 }
75 return;
76}
77
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030078/* Max length of a DIMM label*/
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030079#define EDAC_MC_LABEL_LEN 31
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030080
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030081/* Maximum size of the location string */
Chen, Gong56507692013-10-18 14:30:38 -070082#define LOCATION_SIZE 256
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030083
84/* Defines the maximum number of labels that can be reported */
85#define EDAC_MAX_LABELS 8
86
87/* String used to join two or more labels */
88#define OTHER_LABEL " or "
89
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -030090/**
91 * enum dev_type - describe the type of memory DRAM chips used at the stick
92 * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it
93 * @DEV_X1: 1 bit for data
94 * @DEV_X2: 2 bits for data
95 * @DEV_X4: 4 bits for data
96 * @DEV_X8: 8 bits for data
97 * @DEV_X16: 16 bits for data
98 * @DEV_X32: 32 bits for data
99 * @DEV_X64: 64 bits for data
100 *
101 * Typical values are x4 and x8.
102 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300103enum dev_type {
104 DEV_UNKNOWN = 0,
105 DEV_X1,
106 DEV_X2,
107 DEV_X4,
108 DEV_X8,
109 DEV_X16,
110 DEV_X32, /* Do these parts exist? */
111 DEV_X64 /* Do these parts exist? */
112};
113
114#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
115#define DEV_FLAG_X1 BIT(DEV_X1)
116#define DEV_FLAG_X2 BIT(DEV_X2)
117#define DEV_FLAG_X4 BIT(DEV_X4)
118#define DEV_FLAG_X8 BIT(DEV_X8)
119#define DEV_FLAG_X16 BIT(DEV_X16)
120#define DEV_FLAG_X32 BIT(DEV_X32)
121#define DEV_FLAG_X64 BIT(DEV_X64)
122
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300123/**
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300124 * enum hw_event_mc_err_type - type of the detected error
125 *
126 * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
127 * corrected error was detected
128 * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that
129 * can't be corrected by ECC, but it is not
130 * fatal (maybe it is on an unused memory area,
131 * or the memory controller could recover from
132 * it for example, by re-trying the operation).
133 * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not
134 * be recovered.
135 */
136enum hw_event_mc_err_type {
137 HW_EVENT_ERR_CORRECTED,
138 HW_EVENT_ERR_UNCORRECTED,
Yazen Ghannamd12a9692016-11-17 17:57:32 -0500139 HW_EVENT_ERR_DEFERRED,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300140 HW_EVENT_ERR_FATAL,
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300141 HW_EVENT_ERR_INFO,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300142};
143
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300144static inline char *mc_event_error_type(const unsigned int err_type)
145{
146 switch (err_type) {
147 case HW_EVENT_ERR_CORRECTED:
148 return "Corrected";
149 case HW_EVENT_ERR_UNCORRECTED:
150 return "Uncorrected";
Yazen Ghannamd12a9692016-11-17 17:57:32 -0500151 case HW_EVENT_ERR_DEFERRED:
152 return "Deferred";
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300153 case HW_EVENT_ERR_FATAL:
154 return "Fatal";
155 default:
156 case HW_EVENT_ERR_INFO:
157 return "Info";
158 }
159}
160
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300161/**
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300162 * enum mem_type - memory types. For a more detailed reference, please see
163 * http://en.wikipedia.org/wiki/DRAM
164 *
165 * @MEM_EMPTY Empty csrow
166 * @MEM_RESERVED: Reserved csrow type
167 * @MEM_UNKNOWN: Unknown csrow type
168 * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
169 * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
170 * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
171 * @MEM_SDR: SDR - Single data rate SDRAM
172 * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
173 * They use 3 pins for chip select: Pins 0 and 2 are
174 * for rank 0; pins 1 and 3 are for rank 1, if the memory
175 * is dual-rank.
176 * @MEM_RDR: Registered SDR SDRAM
177 * @MEM_DDR: Double data rate SDRAM
178 * http://en.wikipedia.org/wiki/DDR_SDRAM
179 * @MEM_RDDR: Registered Double data rate SDRAM
180 * This is a variant of the DDR memories.
181 * A registered memory has a buffer inside it, hiding
182 * part of the memory details to the memory controller.
183 * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
184 * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
185 * Those memories are labed as "PC2-" instead of "PC" to
186 * differenciate from DDR.
187 * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
188 * and JESD206.
189 * Those memories are accessed per DIMM slot, and not by
190 * a chip select signal.
191 * @MEM_RDDR2: Registered DDR2 RAM
192 * This is a variant of the DDR2 memories.
193 * @MEM_XDR: Rambus XDR
194 * It is an evolution of the original RAMBUS memories,
195 * created to compete with DDR2. Weren't used on any
196 * x86 arch, but cell_edac PPC memory controller uses it.
197 * @MEM_DDR3: DDR3 RAM
198 * @MEM_RDDR3: Registered DDR3 RAM
199 * This is a variant of the DDR3 memories.
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500200 * @MEM_LRDDR3: Load-Reduced DDR3 memory.
Aravind Gopalakrishnan348fec72014-09-18 14:56:58 -0500201 * @MEM_DDR4: Unbuffered DDR4 RAM
Aristeu Rozanski7b827832014-06-18 11:05:01 -0300202 * @MEM_RDDR4: Registered DDR4 RAM
203 * This is a variant of the DDR4 memories.
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500204 * @MEM_LRDDR4: Load-Reduced DDR4 memory.
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300205 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300206enum mem_type {
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300207 MEM_EMPTY = 0,
208 MEM_RESERVED,
209 MEM_UNKNOWN,
210 MEM_FPM,
211 MEM_EDO,
212 MEM_BEDO,
213 MEM_SDR,
214 MEM_RDR,
215 MEM_DDR,
216 MEM_RDDR,
217 MEM_RMBS,
218 MEM_DDR2,
219 MEM_FB_DDR2,
220 MEM_RDDR2,
221 MEM_XDR,
222 MEM_DDR3,
223 MEM_RDDR3,
Aravind Gopalakrishnan348fec72014-09-18 14:56:58 -0500224 MEM_LRDDR3,
Aristeu Rozanski7b827832014-06-18 11:05:01 -0300225 MEM_DDR4,
226 MEM_RDDR4,
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500227 MEM_LRDDR4,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300228};
229
230#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
231#define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
232#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
233#define MEM_FLAG_FPM BIT(MEM_FPM)
234#define MEM_FLAG_EDO BIT(MEM_EDO)
235#define MEM_FLAG_BEDO BIT(MEM_BEDO)
236#define MEM_FLAG_SDR BIT(MEM_SDR)
237#define MEM_FLAG_RDR BIT(MEM_RDR)
238#define MEM_FLAG_DDR BIT(MEM_DDR)
239#define MEM_FLAG_RDDR BIT(MEM_RDDR)
240#define MEM_FLAG_RMBS BIT(MEM_RMBS)
241#define MEM_FLAG_DDR2 BIT(MEM_DDR2)
242#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
243#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
244#define MEM_FLAG_XDR BIT(MEM_XDR)
Jim Snow255379a2015-12-03 10:48:51 +0100245#define MEM_FLAG_DDR3 BIT(MEM_DDR3)
246#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
247#define MEM_FLAG_DDR4 BIT(MEM_DDR4)
248#define MEM_FLAG_RDDR4 BIT(MEM_RDDR4)
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500249#define MEM_FLAG_LRDDR4 BIT(MEM_LRDDR4)
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300250
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300251/**
252 * enum edac-type - Error Detection and Correction capabilities and mode
253 * @EDAC_UNKNOWN: Unknown if ECC is available
254 * @EDAC_NONE: Doesn't support ECC
255 * @EDAC_RESERVED: Reserved ECC type
256 * @EDAC_PARITY: Detects parity errors
257 * @EDAC_EC: Error Checking - no correction
258 * @EDAC_SECDED: Single bit error correction, Double detection
259 * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist?
260 * @EDAC_S4ECD4ED: Chipkill x4 devices
261 * @EDAC_S8ECD8ED: Chipkill x8 devices
262 * @EDAC_S16ECD16ED: Chipkill x16 devices
263 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300264enum edac_type {
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300265 EDAC_UNKNOWN = 0,
266 EDAC_NONE,
267 EDAC_RESERVED,
268 EDAC_PARITY,
269 EDAC_EC,
270 EDAC_SECDED,
271 EDAC_S2ECD2ED,
272 EDAC_S4ECD4ED,
273 EDAC_S8ECD8ED,
274 EDAC_S16ECD16ED,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300275};
276
277#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
278#define EDAC_FLAG_NONE BIT(EDAC_NONE)
279#define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
280#define EDAC_FLAG_EC BIT(EDAC_EC)
281#define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
282#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
283#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
284#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
285#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
286
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300287/**
288 * enum scrub_type - scrubbing capabilities
289 * @SCRUB_UNKNOWN Unknown if scrubber is available
290 * @SCRUB_NONE: No scrubber
291 * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing
292 * @SCRUB_SW_SRC: Software scrub only errors
293 * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error
294 * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable
295 * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing
296 * @SCRUB_HW_SRC: Hardware scrub only errors
297 * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error
298 * SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable
299 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300300enum scrub_type {
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300301 SCRUB_UNKNOWN = 0,
302 SCRUB_NONE,
303 SCRUB_SW_PROG,
304 SCRUB_SW_SRC,
305 SCRUB_SW_PROG_SRC,
306 SCRUB_SW_TUNABLE,
307 SCRUB_HW_PROG,
308 SCRUB_HW_SRC,
309 SCRUB_HW_PROG_SRC,
310 SCRUB_HW_TUNABLE
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300311};
312
313#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
314#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
315#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
316#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
317#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
318#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
319#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
320#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
321
322/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
323
324/* EDAC internal operation states */
325#define OP_ALLOC 0x100
326#define OP_RUNNING_POLL 0x201
327#define OP_RUNNING_INTERRUPT 0x202
328#define OP_RUNNING_POLL_INTR 0x203
329#define OP_OFFLINE 0x300
330
331/*
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300332 * Concepts used at the EDAC subsystem
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300333 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300334 * There are several things to be aware of that aren't at all obvious:
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300335 *
336 * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
337 *
338 * These are some of the many terms that are thrown about that don't always
339 * mean what people think they mean (Inconceivable!). In the interest of
340 * creating a common ground for discussion, terms and their definitions
341 * will be established.
342 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300343 * Memory devices: The individual DRAM chips on a memory stick. These
344 * devices commonly output 4 and 8 bits each (x4, x8).
345 * Grouping several of these in parallel provides the
346 * number of bits that the memory controller expects:
347 * typically 72 bits, in order to provide 64 bits +
348 * 8 bits of ECC data.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300349 *
350 * Memory Stick: A printed circuit board that aggregates multiple
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300351 * memory devices in parallel. In general, this is the
352 * Field Replaceable Unit (FRU) which gets replaced, in
353 * the case of excessive errors. Most often it is also
354 * called DIMM (Dual Inline Memory Module).
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300355 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300356 * Memory Socket: A physical connector on the motherboard that accepts
357 * a single memory stick. Also called as "slot" on several
358 * datasheets.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300359 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300360 * Channel: A memory controller channel, responsible to communicate
361 * with a group of DIMMs. Each channel has its own
362 * independent control (command) and data bus, and can
363 * be used independently or grouped with other channels.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300364 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300365 * Branch: It is typically the highest hierarchy on a
366 * Fully-Buffered DIMM memory controller.
367 * Typically, it contains two channels.
368 * Two channels at the same branch can be used in single
369 * mode or in lockstep mode.
370 * When lockstep is enabled, the cacheline is doubled,
371 * but it generally brings some performance penalty.
372 * Also, it is generally not possible to point to just one
373 * memory stick when an error occurs, as the error
374 * correction code is calculated using two DIMMs instead
375 * of one. Due to that, it is capable of correcting more
376 * errors than on single mode.
377 *
378 * Single-channel: The data accessed by the memory controller is contained
379 * into one dimm only. E. g. if the data is 64 bits-wide,
380 * the data flows to the CPU using one 64 bits parallel
381 * access.
382 * Typically used with SDR, DDR, DDR2 and DDR3 memories.
383 * FB-DIMM and RAMBUS use a different concept for channel,
384 * so this concept doesn't apply there.
385 *
386 * Double-channel: The data size accessed by the memory controller is
387 * interlaced into two dimms, accessed at the same time.
388 * E. g. if the DIMM is 64 bits-wide (72 bits with ECC),
389 * the data flows to the CPU using a 128 bits parallel
390 * access.
391 *
392 * Chip-select row: This is the name of the DRAM signal used to select the
393 * DRAM ranks to be accessed. Common chip-select rows for
394 * single channel are 64 bits, for dual channel 128 bits.
395 * It may not be visible by the memory controller, as some
396 * DIMM types have a memory buffer that can hide direct
397 * access to it from the Memory Controller.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300398 *
399 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
400 * Motherboards commonly drive two chip-select pins to
401 * a memory stick. A single-ranked stick, will occupy
402 * only one of those rows. The other will be unused.
403 *
404 * Double-Ranked stick: A double-ranked stick has two chip-select rows which
405 * access different sets of memory devices. The two
406 * rows cannot be accessed concurrently.
407 *
408 * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
409 * A double-sided stick has two chip-select rows which
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300410 * access different sets of memory devices. The two
411 * rows cannot be accessed concurrently. "Double-sided"
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300412 * is irrespective of the memory devices being mounted
413 * on both sides of the memory stick.
414 *
415 * Socket set: All of the memory sticks that are required for
416 * a single memory access or all of the memory sticks
417 * spanned by a chip-select row. A single socket set
418 * has two chip-select rows and if double-sided sticks
419 * are used these will occupy those chip-select rows.
420 *
421 * Bank: This term is avoided because it is unclear when
422 * needing to distinguish between chip-select rows and
423 * socket sets.
424 *
425 * Controller pages:
426 *
427 * Physical pages:
428 *
429 * Virtual pages:
430 *
431 *
432 * STRUCTURE ORGANIZATION AND CHOICES
433 *
434 *
435 *
436 * PS - I enjoyed writing all that about as much as you enjoyed reading it.
437 */
438
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300439/**
440 * enum edac_mc_layer - memory controller hierarchy layer
441 *
442 * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch"
443 * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel"
444 * @EDAC_MC_LAYER_SLOT: memory layer is named "slot"
445 * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select"
Mauro Carvalho Chehabc66b5a72013-02-15 07:21:08 -0300446 * @EDAC_MC_LAYER_ALL_MEM: memory layout is unknown. All memory is mapped
447 * as a single memory area. This is used when
448 * retrieving errors from a firmware driven driver.
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300449 *
450 * This enum is used by the drivers to tell edac_mc_sysfs what name should
451 * be used when describing a memory stick location.
452 */
453enum edac_mc_layer_type {
454 EDAC_MC_LAYER_BRANCH,
455 EDAC_MC_LAYER_CHANNEL,
456 EDAC_MC_LAYER_SLOT,
457 EDAC_MC_LAYER_CHIP_SELECT,
Mauro Carvalho Chehabc66b5a72013-02-15 07:21:08 -0300458 EDAC_MC_LAYER_ALL_MEM,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300459};
460
461/**
462 * struct edac_mc_layer - describes the memory controller hierarchy
463 * @layer: layer type
464 * @size: number of components per layer. For example,
465 * if the channel layer has two channels, size = 2
466 * @is_virt_csrow: This layer is part of the "csrow" when old API
467 * compatibility mode is enabled. Otherwise, it is
468 * a channel
469 */
470struct edac_mc_layer {
471 enum edac_mc_layer_type type;
472 unsigned size;
473 bool is_virt_csrow;
474};
475
476/*
477 * Maximum number of layers used by the memory controller to uniquely
478 * identify a single memory stick.
479 * NOTE: Changing this constant requires not only to change the constant
480 * below, but also to change the existing code at the core, as there are
481 * some code there that are optimized for 3 layers.
482 */
483#define EDAC_MAX_LAYERS 3
484
485/**
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300486 * EDAC_DIMM_OFF - Macro responsible to get a pointer offset inside a pointer array
487 * for the element given by [layer0,layer1,layer2] position
488 *
489 * @layers: a struct edac_mc_layer array, describing how many elements
490 * were allocated for each layer
491 * @n_layers: Number of layers at the @layers array
492 * @layer0: layer0 position
493 * @layer1: layer1 position. Unused if n_layers < 2
494 * @layer2: layer2 position. Unused if n_layers < 3
495 *
496 * For 1 layer, this macro returns &var[layer0] - &var
497 * For 2 layers, this macro is similar to allocate a bi-dimensional array
498 * and to return "&var[layer0][layer1] - &var"
499 * For 3 layers, this macro is similar to allocate a tri-dimensional array
500 * and to return "&var[layer0][layer1][layer2] - &var"
501 *
502 * A loop could be used here to make it more generic, but, as we only have
503 * 3 layers, this is a little faster.
504 * By design, layers can never be 0 or more than 3. If that ever happens,
505 * a NULL is returned, causing an OOPS during the memory allocation routine,
506 * with would point to the developer that he's doing something wrong.
507 */
508#define EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2) ({ \
509 int __i; \
510 if ((nlayers) == 1) \
511 __i = layer0; \
512 else if ((nlayers) == 2) \
513 __i = (layer1) + ((layers[1]).size * (layer0)); \
514 else if ((nlayers) == 3) \
515 __i = (layer2) + ((layers[2]).size * ((layer1) + \
516 ((layers[1]).size * (layer0)))); \
517 else \
518 __i = -EINVAL; \
519 __i; \
520})
521
522/**
523 * EDAC_DIMM_PTR - Macro responsible to get a pointer inside a pointer array
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300524 * for the element given by [layer0,layer1,layer2] position
525 *
526 * @layers: a struct edac_mc_layer array, describing how many elements
527 * were allocated for each layer
528 * @var: name of the var where we want to get the pointer
529 * (like mci->dimms)
530 * @n_layers: Number of layers at the @layers array
531 * @layer0: layer0 position
532 * @layer1: layer1 position. Unused if n_layers < 2
533 * @layer2: layer2 position. Unused if n_layers < 3
534 *
535 * For 1 layer, this macro returns &var[layer0]
536 * For 2 layers, this macro is similar to allocate a bi-dimensional array
537 * and to return "&var[layer0][layer1]"
538 * For 3 layers, this macro is similar to allocate a tri-dimensional array
539 * and to return "&var[layer0][layer1][layer2]"
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300540 */
541#define EDAC_DIMM_PTR(layers, var, nlayers, layer0, layer1, layer2) ({ \
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300542 typeof(*var) __p; \
543 int ___i = EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2); \
544 if (___i < 0) \
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300545 __p = NULL; \
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300546 else \
547 __p = (var)[___i]; \
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300548 __p; \
549})
550
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300551struct dimm_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300552 struct device dev;
553
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300554 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300555
556 /* Memory location data */
557 unsigned location[EDAC_MAX_LAYERS];
558
559 struct mem_ctl_info *mci; /* the parent */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300560
561 u32 grain; /* granularity of reported error in bytes */
562 enum dev_type dtype; /* memory device type */
563 enum mem_type mtype; /* memory dimm type */
564 enum edac_type edac_mode; /* EDAC mode for this dimm */
565
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300566 u32 nr_pages; /* number of pages on this dimm */
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300567
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300568 unsigned csrow, cschannel; /* Points to the old API data */
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300569};
570
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300571/**
572 * struct rank_info - contains the information for one DIMM rank
573 *
574 * @chan_idx: channel number where the rank is (typically, 0 or 1)
575 * @ce_count: number of correctable errors for this rank
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300576 * @csrow: A pointer to the chip select row structure (the parent
577 * structure). The location of the rank is given by
578 * the (csrow->csrow_idx, chan_idx) vector.
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300579 * @dimm: A pointer to the DIMM structure, where the DIMM label
580 * information is stored.
581 *
582 * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
583 * This is a bad assumption, but it makes this patch easier. Later
584 * patches in this series will fix this issue.
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300585 */
586struct rank_info {
587 int chan_idx;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300588 struct csrow_info *csrow;
589 struct dimm_info *dimm;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300590
591 u32 ce_count; /* Correctable Errors for this csrow */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300592};
593
594struct csrow_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300595 struct device dev;
596
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300597 /* Used only by edac_mc_find_csrow_by_page() */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300598 unsigned long first_page; /* first page number in csrow */
599 unsigned long last_page; /* last page number in csrow */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300600 unsigned long page_mask; /* used for interleaving -
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300601 * 0UL for non intlv */
602
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300603 int csrow_idx; /* the chip-select row */
604
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300605 u32 ue_count; /* Uncorrectable Errors for this csrow */
606 u32 ce_count; /* Correctable Errors for this csrow */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300607
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300608 struct mem_ctl_info *mci; /* the parent */
609
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300610 /* channel information for this csrow */
611 u32 nr_channels;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300612 struct rank_info **channels;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300613};
614
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300615/*
616 * struct errcount_attribute - used to store the several error counts
617 */
618struct errcount_attribute_data {
619 int n_layers;
620 int pos[EDAC_MAX_LAYERS];
621 int layer0, layer1, layer2;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300622};
623
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300624/**
625 * edac_raw_error_desc - Raw error report structure
626 * @grain: minimum granularity for an error report, in bytes
627 * @error_count: number of errors of the same type
628 * @top_layer: top layer of the error (layer[0])
629 * @mid_layer: middle layer of the error (layer[1])
630 * @low_layer: low layer of the error (layer[2])
631 * @page_frame_number: page where the error happened
632 * @offset_in_page: page offset
633 * @syndrome: syndrome of the error (or 0 if unknown or if
634 * the syndrome is not applicable)
635 * @msg: error message
636 * @location: location of the error
637 * @label: label of the affected DIMM(s)
638 * @other_detail: other driver-specific detail about the error
639 * @enable_per_layer_report: if false, the error affects all layers
640 * (typically, a memory controller error)
641 */
642struct edac_raw_error_desc {
643 /*
644 * NOTE: everything before grain won't be cleaned by
645 * edac_raw_error_desc_clean()
646 */
647 char location[LOCATION_SIZE];
648 char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
649 long grain;
650
651 /* the vars below and grain will be cleaned on every new error report */
652 u16 error_count;
653 int top_layer;
654 int mid_layer;
655 int low_layer;
656 unsigned long page_frame_number;
657 unsigned long offset_in_page;
658 unsigned long syndrome;
659 const char *msg;
660 const char *other_detail;
661 bool enable_per_layer_report;
662};
663
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300664/* MEMORY controller information structure
665 */
666struct mem_ctl_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300667 struct device dev;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200668 struct bus_type *bus;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300669
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300670 struct list_head link; /* for global list of mem_ctl_info structs */
671
672 struct module *owner; /* Module owner of this control struct */
673
674 unsigned long mtype_cap; /* memory types supported by mc */
675 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
676 unsigned long edac_cap; /* configuration capabilities - this is
677 * closely related to edac_ctl_cap. The
678 * difference is that the controller may be
679 * capable of s4ecd4ed which would be listed
680 * in edac_ctl_cap, but if channels aren't
681 * capable of s4ecd4ed then the edac_cap would
682 * not have that capability.
683 */
684 unsigned long scrub_cap; /* chipset scrub capabilities */
685 enum scrub_type scrub_mode; /* current scrub mode */
686
687 /* Translates sdram memory scrub rate given in bytes/sec to the
688 internal representation and configures whatever else needs
689 to be configured.
690 */
691 int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
692
693 /* Get the current sdram memory scrub rate from the internal
694 representation and converts it to the closest matching
695 bandwidth in bytes/sec.
696 */
697 int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
698
699
700 /* pointer to edac checking routine */
701 void (*edac_check) (struct mem_ctl_info * mci);
702
703 /*
704 * Remaps memory pages: controller pages to physical pages.
705 * For most MC's, this will be NULL.
706 */
707 /* FIXME - why not send the phys page to begin with? */
708 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
709 unsigned long page);
710 int mc_idx;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300711 struct csrow_info **csrows;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300712 unsigned nr_csrows, num_cschannel;
713
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300714 /*
715 * Memory Controller hierarchy
716 *
717 * There are basically two types of memory controller: the ones that
718 * sees memory sticks ("dimms"), and the ones that sees memory ranks.
719 * All old memory controllers enumerate memories per rank, but most
720 * of the recent drivers enumerate memories per DIMM, instead.
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300721 * When the memory controller is per rank, csbased is true.
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300722 */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300723 unsigned n_layers;
724 struct edac_mc_layer *layers;
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300725 bool csbased;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300726
727 /*
728 * DIMM info. Will eventually remove the entire csrows_info some day
729 */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300730 unsigned tot_dimms;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300731 struct dimm_info **dimms;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300732
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300733 /*
734 * FIXME - what about controllers on other busses? - IDs must be
735 * unique. dev pointer should be sufficiently unique, but
736 * BUS:SLOT.FUNC numbers may not be unique.
737 */
Mauro Carvalho Chehabfd687502012-03-16 07:44:18 -0300738 struct device *pdev;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300739 const char *mod_name;
740 const char *mod_ver;
741 const char *ctl_name;
742 const char *dev_name;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300743 void *pvt_info;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300744 unsigned long start_time; /* mci load start time (in jiffies) */
745
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300746 /*
747 * drivers shouldn't access those fields directly, as the core
748 * already handles that.
749 */
750 u32 ce_noinfo_count, ue_noinfo_count;
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300751 u32 ue_mc, ce_mc;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300752 u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS];
753
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300754 struct completion complete;
755
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300756 /* Additional top controller level attributes, but specified
757 * by the low level driver.
758 *
759 * Set by the low level driver to provide attributes at the
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300760 * controller level.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300761 * An array of structures, NULL terminated
762 *
763 * If attributes are desired, then set to array of attributes
764 * If no attributes are desired, leave NULL
765 */
766 const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
767
768 /* work struct for this MC */
769 struct delayed_work work;
770
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300771 /*
772 * Used to report an error - by being at the global struct
773 * makes the memory allocated by the EDAC core
774 */
775 struct edac_raw_error_desc error_desc;
776
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300777 /* the internal state of this controller instance */
778 int op_state;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300779
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300780 struct dentry *debugfs;
781 u8 fake_inject_layer[EDAC_MAX_LAYERS];
Viresh Kumar621a5f72015-09-26 15:04:07 -0700782 bool fake_inject_ue;
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300783 u16 fake_inject_count;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300784};
785
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200786/*
787 * Maximum number of memory controllers in the coherent fabric.
788 */
789#define EDAC_MAX_MCS 16
790
Dave Jiangc0d12172007-07-19 01:49:46 -0700791#endif