blob: c6233227720c75c4224260ebd9bdea224b1c6123 [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>
Justin Ernst4d29f082018-09-25 09:34:49 -050020#include <linux/numa.h>
Paul Gortmaker313162d2012-01-30 11:46:54 -050021
22struct device;
Dave Jiangc0d12172007-07-19 01:49:46 -070023
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;
Dave Jiang66ee2f92007-07-19 01:49:54 -070030extern int edac_err_assert;
Dave Jiangc0d12172007-07-19 01:49:46 -070031extern atomic_t edac_handlers;
Dave Jiangc0d12172007-07-19 01:49:46 -070032
33extern int edac_handler_set(void);
34extern void edac_atomic_assert_error(void);
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080035extern struct bus_type *edac_get_sysfs_subsys(void);
Dave Jiangc0d12172007-07-19 01:49:46 -070036
Chen, Gongc700f012013-12-06 01:17:08 -050037enum {
38 EDAC_REPORTING_ENABLED,
39 EDAC_REPORTING_DISABLED,
40 EDAC_REPORTING_FORCE
41};
42
43extern int edac_report_status;
44#ifdef CONFIG_EDAC
45static inline int get_edac_report_status(void)
46{
47 return edac_report_status;
48}
49
50static inline void set_edac_report_status(int new)
51{
52 edac_report_status = new;
53}
54#else
55static inline int get_edac_report_status(void)
56{
57 return EDAC_REPORTING_DISABLED;
58}
59
60static inline void set_edac_report_status(int new)
61{
62}
63#endif
64
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -070065static inline void opstate_init(void)
66{
67 switch (edac_op_state) {
68 case EDAC_OPSTATE_POLL:
69 case EDAC_OPSTATE_NMI:
70 break;
71 default:
72 edac_op_state = EDAC_OPSTATE_POLL;
73 }
74 return;
75}
76
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030077/* Max length of a DIMM label*/
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030078#define EDAC_MC_LABEL_LEN 31
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030079
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030080/* Maximum size of the location string */
Chen, Gong56507692013-10-18 14:30:38 -070081#define LOCATION_SIZE 256
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030082
83/* Defines the maximum number of labels that can be reported */
84#define EDAC_MAX_LABELS 8
85
86/* String used to join two or more labels */
87#define OTHER_LABEL " or "
88
Mauro Carvalho Chehabb0610bb2012-03-21 16:21:07 -030089/**
90 * enum dev_type - describe the type of memory DRAM chips used at the stick
91 * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it
92 * @DEV_X1: 1 bit for data
93 * @DEV_X2: 2 bits for data
94 * @DEV_X4: 4 bits for data
95 * @DEV_X8: 8 bits for data
96 * @DEV_X16: 16 bits for data
97 * @DEV_X32: 32 bits for data
98 * @DEV_X64: 64 bits for data
99 *
100 * Typical values are x4 and x8.
101 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300102enum dev_type {
103 DEV_UNKNOWN = 0,
104 DEV_X1,
105 DEV_X2,
106 DEV_X4,
107 DEV_X8,
108 DEV_X16,
109 DEV_X32, /* Do these parts exist? */
110 DEV_X64 /* Do these parts exist? */
111};
112
113#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
114#define DEV_FLAG_X1 BIT(DEV_X1)
115#define DEV_FLAG_X2 BIT(DEV_X2)
116#define DEV_FLAG_X4 BIT(DEV_X4)
117#define DEV_FLAG_X8 BIT(DEV_X8)
118#define DEV_FLAG_X16 BIT(DEV_X16)
119#define DEV_FLAG_X32 BIT(DEV_X32)
120#define DEV_FLAG_X64 BIT(DEV_X64)
121
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300122/**
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300123 * enum hw_event_mc_err_type - type of the detected error
124 *
125 * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
126 * corrected error was detected
127 * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that
128 * can't be corrected by ECC, but it is not
129 * fatal (maybe it is on an unused memory area,
130 * or the memory controller could recover from
131 * it for example, by re-trying the operation).
132 * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not
133 * be recovered.
134 */
135enum hw_event_mc_err_type {
136 HW_EVENT_ERR_CORRECTED,
137 HW_EVENT_ERR_UNCORRECTED,
138 HW_EVENT_ERR_FATAL,
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300139 HW_EVENT_ERR_INFO,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300140};
141
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300142static inline char *mc_event_error_type(const unsigned int err_type)
143{
144 switch (err_type) {
145 case HW_EVENT_ERR_CORRECTED:
146 return "Corrected";
147 case HW_EVENT_ERR_UNCORRECTED:
148 return "Uncorrected";
149 case HW_EVENT_ERR_FATAL:
150 return "Fatal";
151 default:
152 case HW_EVENT_ERR_INFO:
153 return "Info";
154 }
155}
156
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300157/**
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300158 * enum mem_type - memory types. For a more detailed reference, please see
159 * http://en.wikipedia.org/wiki/DRAM
160 *
161 * @MEM_EMPTY Empty csrow
162 * @MEM_RESERVED: Reserved csrow type
163 * @MEM_UNKNOWN: Unknown csrow type
164 * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
165 * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
166 * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
167 * @MEM_SDR: SDR - Single data rate SDRAM
168 * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
169 * They use 3 pins for chip select: Pins 0 and 2 are
170 * for rank 0; pins 1 and 3 are for rank 1, if the memory
171 * is dual-rank.
172 * @MEM_RDR: Registered SDR SDRAM
173 * @MEM_DDR: Double data rate SDRAM
174 * http://en.wikipedia.org/wiki/DDR_SDRAM
175 * @MEM_RDDR: Registered Double data rate SDRAM
176 * This is a variant of the DDR memories.
177 * A registered memory has a buffer inside it, hiding
178 * part of the memory details to the memory controller.
179 * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
180 * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
181 * Those memories are labed as "PC2-" instead of "PC" to
182 * differenciate from DDR.
183 * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
184 * and JESD206.
185 * Those memories are accessed per DIMM slot, and not by
186 * a chip select signal.
187 * @MEM_RDDR2: Registered DDR2 RAM
188 * This is a variant of the DDR2 memories.
189 * @MEM_XDR: Rambus XDR
190 * It is an evolution of the original RAMBUS memories,
191 * created to compete with DDR2. Weren't used on any
192 * x86 arch, but cell_edac PPC memory controller uses it.
193 * @MEM_DDR3: DDR3 RAM
194 * @MEM_RDDR3: Registered DDR3 RAM
195 * This is a variant of the DDR3 memories.
Aravind Gopalakrishnan348fec72014-09-18 14:56:58 -0500196 * @MEM_LRDDR3 Load-Reduced DDR3 memory.
197 * @MEM_DDR4: Unbuffered DDR4 RAM
Aristeu Rozanski7b827832014-06-18 11:05:01 -0300198 * @MEM_RDDR4: Registered DDR4 RAM
199 * This is a variant of the DDR4 memories.
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300200 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300201enum mem_type {
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300202 MEM_EMPTY = 0,
203 MEM_RESERVED,
204 MEM_UNKNOWN,
205 MEM_FPM,
206 MEM_EDO,
207 MEM_BEDO,
208 MEM_SDR,
209 MEM_RDR,
210 MEM_DDR,
211 MEM_RDDR,
212 MEM_RMBS,
213 MEM_DDR2,
214 MEM_FB_DDR2,
215 MEM_RDDR2,
216 MEM_XDR,
217 MEM_DDR3,
218 MEM_RDDR3,
Aravind Gopalakrishnan348fec72014-09-18 14:56:58 -0500219 MEM_LRDDR3,
Aristeu Rozanski7b827832014-06-18 11:05:01 -0300220 MEM_DDR4,
221 MEM_RDDR4,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300222};
223
224#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
225#define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
226#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
227#define MEM_FLAG_FPM BIT(MEM_FPM)
228#define MEM_FLAG_EDO BIT(MEM_EDO)
229#define MEM_FLAG_BEDO BIT(MEM_BEDO)
230#define MEM_FLAG_SDR BIT(MEM_SDR)
231#define MEM_FLAG_RDR BIT(MEM_RDR)
232#define MEM_FLAG_DDR BIT(MEM_DDR)
233#define MEM_FLAG_RDDR BIT(MEM_RDDR)
234#define MEM_FLAG_RMBS BIT(MEM_RMBS)
235#define MEM_FLAG_DDR2 BIT(MEM_DDR2)
236#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
237#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
238#define MEM_FLAG_XDR BIT(MEM_XDR)
Jim Snow255379a2015-12-03 10:48:51 +0100239#define MEM_FLAG_DDR3 BIT(MEM_DDR3)
240#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
241#define MEM_FLAG_DDR4 BIT(MEM_DDR4)
242#define MEM_FLAG_RDDR4 BIT(MEM_RDDR4)
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300243
Mauro Carvalho Chehabb0610bb2012-03-21 16:21:07 -0300244/**
245 * enum edac-type - Error Detection and Correction capabilities and mode
246 * @EDAC_UNKNOWN: Unknown if ECC is available
247 * @EDAC_NONE: Doesn't support ECC
248 * @EDAC_RESERVED: Reserved ECC type
249 * @EDAC_PARITY: Detects parity errors
250 * @EDAC_EC: Error Checking - no correction
251 * @EDAC_SECDED: Single bit error correction, Double detection
252 * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist?
253 * @EDAC_S4ECD4ED: Chipkill x4 devices
254 * @EDAC_S8ECD8ED: Chipkill x8 devices
255 * @EDAC_S16ECD16ED: Chipkill x16 devices
256 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300257enum edac_type {
Mauro Carvalho Chehabb0610bb2012-03-21 16:21:07 -0300258 EDAC_UNKNOWN = 0,
259 EDAC_NONE,
260 EDAC_RESERVED,
261 EDAC_PARITY,
262 EDAC_EC,
263 EDAC_SECDED,
264 EDAC_S2ECD2ED,
265 EDAC_S4ECD4ED,
266 EDAC_S8ECD8ED,
267 EDAC_S16ECD16ED,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300268};
269
270#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
271#define EDAC_FLAG_NONE BIT(EDAC_NONE)
272#define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
273#define EDAC_FLAG_EC BIT(EDAC_EC)
274#define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
275#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
276#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
277#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
278#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
279
Mauro Carvalho Chehabb0610bb2012-03-21 16:21:07 -0300280/**
281 * enum scrub_type - scrubbing capabilities
282 * @SCRUB_UNKNOWN Unknown if scrubber is available
283 * @SCRUB_NONE: No scrubber
284 * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing
285 * @SCRUB_SW_SRC: Software scrub only errors
286 * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error
287 * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable
288 * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing
289 * @SCRUB_HW_SRC: Hardware scrub only errors
290 * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error
291 * SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable
292 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300293enum scrub_type {
Mauro Carvalho Chehabb0610bb2012-03-21 16:21:07 -0300294 SCRUB_UNKNOWN = 0,
295 SCRUB_NONE,
296 SCRUB_SW_PROG,
297 SCRUB_SW_SRC,
298 SCRUB_SW_PROG_SRC,
299 SCRUB_SW_TUNABLE,
300 SCRUB_HW_PROG,
301 SCRUB_HW_SRC,
302 SCRUB_HW_PROG_SRC,
303 SCRUB_HW_TUNABLE
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300304};
305
306#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
307#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
308#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
309#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
310#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
311#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
312#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
313#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
314
315/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
316
317/* EDAC internal operation states */
318#define OP_ALLOC 0x100
319#define OP_RUNNING_POLL 0x201
320#define OP_RUNNING_INTERRUPT 0x202
321#define OP_RUNNING_POLL_INTR 0x203
322#define OP_OFFLINE 0x300
323
324/*
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300325 * Concepts used at the EDAC subsystem
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300326 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300327 * There are several things to be aware of that aren't at all obvious:
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300328 *
329 * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
330 *
331 * These are some of the many terms that are thrown about that don't always
332 * mean what people think they mean (Inconceivable!). In the interest of
333 * creating a common ground for discussion, terms and their definitions
334 * will be established.
335 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300336 * Memory devices: The individual DRAM chips on a memory stick. These
337 * devices commonly output 4 and 8 bits each (x4, x8).
338 * Grouping several of these in parallel provides the
339 * number of bits that the memory controller expects:
340 * typically 72 bits, in order to provide 64 bits +
341 * 8 bits of ECC data.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300342 *
343 * Memory Stick: A printed circuit board that aggregates multiple
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300344 * memory devices in parallel. In general, this is the
345 * Field Replaceable Unit (FRU) which gets replaced, in
346 * the case of excessive errors. Most often it is also
347 * called DIMM (Dual Inline Memory Module).
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300348 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300349 * Memory Socket: A physical connector on the motherboard that accepts
350 * a single memory stick. Also called as "slot" on several
351 * datasheets.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300352 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300353 * Channel: A memory controller channel, responsible to communicate
354 * with a group of DIMMs. Each channel has its own
355 * independent control (command) and data bus, and can
356 * be used independently or grouped with other channels.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300357 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300358 * Branch: It is typically the highest hierarchy on a
359 * Fully-Buffered DIMM memory controller.
360 * Typically, it contains two channels.
361 * Two channels at the same branch can be used in single
362 * mode or in lockstep mode.
363 * When lockstep is enabled, the cacheline is doubled,
364 * but it generally brings some performance penalty.
365 * Also, it is generally not possible to point to just one
366 * memory stick when an error occurs, as the error
367 * correction code is calculated using two DIMMs instead
368 * of one. Due to that, it is capable of correcting more
369 * errors than on single mode.
370 *
371 * Single-channel: The data accessed by the memory controller is contained
372 * into one dimm only. E. g. if the data is 64 bits-wide,
373 * the data flows to the CPU using one 64 bits parallel
374 * access.
375 * Typically used with SDR, DDR, DDR2 and DDR3 memories.
376 * FB-DIMM and RAMBUS use a different concept for channel,
377 * so this concept doesn't apply there.
378 *
379 * Double-channel: The data size accessed by the memory controller is
380 * interlaced into two dimms, accessed at the same time.
381 * E. g. if the DIMM is 64 bits-wide (72 bits with ECC),
382 * the data flows to the CPU using a 128 bits parallel
383 * access.
384 *
385 * Chip-select row: This is the name of the DRAM signal used to select the
386 * DRAM ranks to be accessed. Common chip-select rows for
387 * single channel are 64 bits, for dual channel 128 bits.
388 * It may not be visible by the memory controller, as some
389 * DIMM types have a memory buffer that can hide direct
390 * access to it from the Memory Controller.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300391 *
392 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
393 * Motherboards commonly drive two chip-select pins to
394 * a memory stick. A single-ranked stick, will occupy
395 * only one of those rows. The other will be unused.
396 *
397 * Double-Ranked stick: A double-ranked stick has two chip-select rows which
398 * access different sets of memory devices. The two
399 * rows cannot be accessed concurrently.
400 *
401 * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
402 * A double-sided stick has two chip-select rows which
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300403 * access different sets of memory devices. The two
404 * rows cannot be accessed concurrently. "Double-sided"
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300405 * is irrespective of the memory devices being mounted
406 * on both sides of the memory stick.
407 *
408 * Socket set: All of the memory sticks that are required for
409 * a single memory access or all of the memory sticks
410 * spanned by a chip-select row. A single socket set
411 * has two chip-select rows and if double-sided sticks
412 * are used these will occupy those chip-select rows.
413 *
414 * Bank: This term is avoided because it is unclear when
415 * needing to distinguish between chip-select rows and
416 * socket sets.
417 *
418 * Controller pages:
419 *
420 * Physical pages:
421 *
422 * Virtual pages:
423 *
424 *
425 * STRUCTURE ORGANIZATION AND CHOICES
426 *
427 *
428 *
429 * PS - I enjoyed writing all that about as much as you enjoyed reading it.
430 */
431
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300432/**
433 * enum edac_mc_layer - memory controller hierarchy layer
434 *
435 * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch"
436 * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel"
437 * @EDAC_MC_LAYER_SLOT: memory layer is named "slot"
438 * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select"
Mauro Carvalho Chehabc66b5a72013-02-15 07:21:08 -0300439 * @EDAC_MC_LAYER_ALL_MEM: memory layout is unknown. All memory is mapped
440 * as a single memory area. This is used when
441 * retrieving errors from a firmware driven driver.
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300442 *
443 * This enum is used by the drivers to tell edac_mc_sysfs what name should
444 * be used when describing a memory stick location.
445 */
446enum edac_mc_layer_type {
447 EDAC_MC_LAYER_BRANCH,
448 EDAC_MC_LAYER_CHANNEL,
449 EDAC_MC_LAYER_SLOT,
450 EDAC_MC_LAYER_CHIP_SELECT,
Mauro Carvalho Chehabc66b5a72013-02-15 07:21:08 -0300451 EDAC_MC_LAYER_ALL_MEM,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300452};
453
454/**
455 * struct edac_mc_layer - describes the memory controller hierarchy
456 * @layer: layer type
457 * @size: number of components per layer. For example,
458 * if the channel layer has two channels, size = 2
459 * @is_virt_csrow: This layer is part of the "csrow" when old API
460 * compatibility mode is enabled. Otherwise, it is
461 * a channel
462 */
463struct edac_mc_layer {
464 enum edac_mc_layer_type type;
465 unsigned size;
466 bool is_virt_csrow;
467};
468
469/*
470 * Maximum number of layers used by the memory controller to uniquely
471 * identify a single memory stick.
472 * NOTE: Changing this constant requires not only to change the constant
473 * below, but also to change the existing code at the core, as there are
474 * some code there that are optimized for 3 layers.
475 */
476#define EDAC_MAX_LAYERS 3
477
478/**
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300479 * EDAC_DIMM_OFF - Macro responsible to get a pointer offset inside a pointer array
480 * for the element given by [layer0,layer1,layer2] position
481 *
482 * @layers: a struct edac_mc_layer array, describing how many elements
483 * were allocated for each layer
484 * @n_layers: Number of layers at the @layers array
485 * @layer0: layer0 position
486 * @layer1: layer1 position. Unused if n_layers < 2
487 * @layer2: layer2 position. Unused if n_layers < 3
488 *
489 * For 1 layer, this macro returns &var[layer0] - &var
490 * For 2 layers, this macro is similar to allocate a bi-dimensional array
491 * and to return "&var[layer0][layer1] - &var"
492 * For 3 layers, this macro is similar to allocate a tri-dimensional array
493 * and to return "&var[layer0][layer1][layer2] - &var"
494 *
495 * A loop could be used here to make it more generic, but, as we only have
496 * 3 layers, this is a little faster.
497 * By design, layers can never be 0 or more than 3. If that ever happens,
498 * a NULL is returned, causing an OOPS during the memory allocation routine,
499 * with would point to the developer that he's doing something wrong.
500 */
501#define EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2) ({ \
502 int __i; \
503 if ((nlayers) == 1) \
504 __i = layer0; \
505 else if ((nlayers) == 2) \
506 __i = (layer1) + ((layers[1]).size * (layer0)); \
507 else if ((nlayers) == 3) \
508 __i = (layer2) + ((layers[2]).size * ((layer1) + \
509 ((layers[1]).size * (layer0)))); \
510 else \
511 __i = -EINVAL; \
512 __i; \
513})
514
515/**
516 * EDAC_DIMM_PTR - Macro responsible to get a pointer inside a pointer array
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300517 * for the element given by [layer0,layer1,layer2] position
518 *
519 * @layers: a struct edac_mc_layer array, describing how many elements
520 * were allocated for each layer
521 * @var: name of the var where we want to get the pointer
522 * (like mci->dimms)
523 * @n_layers: Number of layers at the @layers array
524 * @layer0: layer0 position
525 * @layer1: layer1 position. Unused if n_layers < 2
526 * @layer2: layer2 position. Unused if n_layers < 3
527 *
528 * For 1 layer, this macro returns &var[layer0]
529 * For 2 layers, this macro is similar to allocate a bi-dimensional array
530 * and to return "&var[layer0][layer1]"
531 * For 3 layers, this macro is similar to allocate a tri-dimensional array
532 * and to return "&var[layer0][layer1][layer2]"
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300533 */
534#define EDAC_DIMM_PTR(layers, var, nlayers, layer0, layer1, layer2) ({ \
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300535 typeof(*var) __p; \
536 int ___i = EDAC_DIMM_OFF(layers, nlayers, layer0, layer1, layer2); \
537 if (___i < 0) \
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300538 __p = NULL; \
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300539 else \
540 __p = (var)[___i]; \
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300541 __p; \
542})
543
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300544struct dimm_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300545 struct device dev;
546
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300547 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300548
549 /* Memory location data */
550 unsigned location[EDAC_MAX_LAYERS];
551
552 struct mem_ctl_info *mci; /* the parent */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300553
554 u32 grain; /* granularity of reported error in bytes */
555 enum dev_type dtype; /* memory device type */
556 enum mem_type mtype; /* memory dimm type */
557 enum edac_type edac_mode; /* EDAC mode for this dimm */
558
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300559 u32 nr_pages; /* number of pages on this dimm */
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300560
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300561 unsigned csrow, cschannel; /* Points to the old API data */
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300562};
563
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300564/**
565 * struct rank_info - contains the information for one DIMM rank
566 *
567 * @chan_idx: channel number where the rank is (typically, 0 or 1)
568 * @ce_count: number of correctable errors for this rank
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300569 * @csrow: A pointer to the chip select row structure (the parent
570 * structure). The location of the rank is given by
571 * the (csrow->csrow_idx, chan_idx) vector.
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300572 * @dimm: A pointer to the DIMM structure, where the DIMM label
573 * information is stored.
574 *
575 * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
576 * This is a bad assumption, but it makes this patch easier. Later
577 * patches in this series will fix this issue.
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300578 */
579struct rank_info {
580 int chan_idx;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300581 struct csrow_info *csrow;
582 struct dimm_info *dimm;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300583
584 u32 ce_count; /* Correctable Errors for this csrow */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300585};
586
587struct csrow_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300588 struct device dev;
589
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300590 /* Used only by edac_mc_find_csrow_by_page() */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300591 unsigned long first_page; /* first page number in csrow */
592 unsigned long last_page; /* last page number in csrow */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300593 unsigned long page_mask; /* used for interleaving -
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300594 * 0UL for non intlv */
595
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300596 int csrow_idx; /* the chip-select row */
597
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300598 u32 ue_count; /* Uncorrectable Errors for this csrow */
599 u32 ce_count; /* Correctable Errors for this csrow */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300600
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300601 struct mem_ctl_info *mci; /* the parent */
602
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300603 /* channel information for this csrow */
604 u32 nr_channels;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300605 struct rank_info **channels;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300606};
607
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300608/*
609 * struct errcount_attribute - used to store the several error counts
610 */
611struct errcount_attribute_data {
612 int n_layers;
613 int pos[EDAC_MAX_LAYERS];
614 int layer0, layer1, layer2;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300615};
616
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300617/**
618 * edac_raw_error_desc - Raw error report structure
619 * @grain: minimum granularity for an error report, in bytes
620 * @error_count: number of errors of the same type
621 * @top_layer: top layer of the error (layer[0])
622 * @mid_layer: middle layer of the error (layer[1])
623 * @low_layer: low layer of the error (layer[2])
624 * @page_frame_number: page where the error happened
625 * @offset_in_page: page offset
626 * @syndrome: syndrome of the error (or 0 if unknown or if
627 * the syndrome is not applicable)
628 * @msg: error message
629 * @location: location of the error
630 * @label: label of the affected DIMM(s)
631 * @other_detail: other driver-specific detail about the error
632 * @enable_per_layer_report: if false, the error affects all layers
633 * (typically, a memory controller error)
634 */
635struct edac_raw_error_desc {
636 /*
637 * NOTE: everything before grain won't be cleaned by
638 * edac_raw_error_desc_clean()
639 */
640 char location[LOCATION_SIZE];
641 char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
642 long grain;
643
644 /* the vars below and grain will be cleaned on every new error report */
645 u16 error_count;
646 int top_layer;
647 int mid_layer;
648 int low_layer;
649 unsigned long page_frame_number;
650 unsigned long offset_in_page;
651 unsigned long syndrome;
652 const char *msg;
653 const char *other_detail;
654 bool enable_per_layer_report;
655};
656
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300657/* MEMORY controller information structure
658 */
659struct mem_ctl_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300660 struct device dev;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200661 struct bus_type *bus;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300662
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300663 struct list_head link; /* for global list of mem_ctl_info structs */
664
665 struct module *owner; /* Module owner of this control struct */
666
667 unsigned long mtype_cap; /* memory types supported by mc */
668 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
669 unsigned long edac_cap; /* configuration capabilities - this is
670 * closely related to edac_ctl_cap. The
671 * difference is that the controller may be
672 * capable of s4ecd4ed which would be listed
673 * in edac_ctl_cap, but if channels aren't
674 * capable of s4ecd4ed then the edac_cap would
675 * not have that capability.
676 */
677 unsigned long scrub_cap; /* chipset scrub capabilities */
678 enum scrub_type scrub_mode; /* current scrub mode */
679
680 /* Translates sdram memory scrub rate given in bytes/sec to the
681 internal representation and configures whatever else needs
682 to be configured.
683 */
684 int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
685
686 /* Get the current sdram memory scrub rate from the internal
687 representation and converts it to the closest matching
688 bandwidth in bytes/sec.
689 */
690 int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
691
692
693 /* pointer to edac checking routine */
694 void (*edac_check) (struct mem_ctl_info * mci);
695
696 /*
697 * Remaps memory pages: controller pages to physical pages.
698 * For most MC's, this will be NULL.
699 */
700 /* FIXME - why not send the phys page to begin with? */
701 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
702 unsigned long page);
703 int mc_idx;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300704 struct csrow_info **csrows;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300705 unsigned nr_csrows, num_cschannel;
706
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300707 /*
708 * Memory Controller hierarchy
709 *
710 * There are basically two types of memory controller: the ones that
711 * sees memory sticks ("dimms"), and the ones that sees memory ranks.
712 * All old memory controllers enumerate memories per rank, but most
713 * of the recent drivers enumerate memories per DIMM, instead.
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300714 * When the memory controller is per rank, csbased is true.
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300715 */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300716 unsigned n_layers;
717 struct edac_mc_layer *layers;
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300718 bool csbased;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300719
720 /*
721 * DIMM info. Will eventually remove the entire csrows_info some day
722 */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300723 unsigned tot_dimms;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300724 struct dimm_info **dimms;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300725
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300726 /*
727 * FIXME - what about controllers on other busses? - IDs must be
728 * unique. dev pointer should be sufficiently unique, but
729 * BUS:SLOT.FUNC numbers may not be unique.
730 */
Mauro Carvalho Chehabfd687502012-03-16 07:44:18 -0300731 struct device *pdev;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300732 const char *mod_name;
733 const char *mod_ver;
734 const char *ctl_name;
735 const char *dev_name;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300736 void *pvt_info;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300737 unsigned long start_time; /* mci load start time (in jiffies) */
738
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300739 /*
740 * drivers shouldn't access those fields directly, as the core
741 * already handles that.
742 */
743 u32 ce_noinfo_count, ue_noinfo_count;
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300744 u32 ue_mc, ce_mc;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300745 u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS];
746
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300747 struct completion complete;
748
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300749 /* Additional top controller level attributes, but specified
750 * by the low level driver.
751 *
752 * Set by the low level driver to provide attributes at the
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300753 * controller level.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300754 * An array of structures, NULL terminated
755 *
756 * If attributes are desired, then set to array of attributes
757 * If no attributes are desired, leave NULL
758 */
759 const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
760
761 /* work struct for this MC */
762 struct delayed_work work;
763
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300764 /*
765 * Used to report an error - by being at the global struct
766 * makes the memory allocated by the EDAC core
767 */
768 struct edac_raw_error_desc error_desc;
769
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300770 /* the internal state of this controller instance */
771 int op_state;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300772
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300773 struct dentry *debugfs;
774 u8 fake_inject_layer[EDAC_MAX_LAYERS];
Viresh Kumar621a5f72015-09-26 15:04:07 -0700775 bool fake_inject_ue;
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300776 u16 fake_inject_count;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300777};
778
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200779/*
780 * Maximum number of memory controllers in the coherent fabric.
781 */
Justin Ernst4d29f082018-09-25 09:34:49 -0500782#define EDAC_MAX_MCS 2 * MAX_NUMNODES
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200783
Dave Jiangc0d12172007-07-19 01:49:46 -0700784#endif