blob: 0f20b986b0abd09ac6fd4063a1107df4ff13e688 [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 Ernst6b588592018-09-25 09:34:49 -050020#include <linux/numa.h>
Paul Gortmaker313162d2012-01-30 11:46:54 -050021
Mauro Carvalho Chehab0b892c72016-10-29 09:56:00 -020022#define EDAC_DEVICE_NAME_LEN 31
23
Paul Gortmaker313162d2012-01-30 11:46:54 -050024struct device;
Dave Jiangc0d12172007-07-19 01:49:46 -070025
26#define EDAC_OPSTATE_INVAL -1
27#define EDAC_OPSTATE_POLL 0
28#define EDAC_OPSTATE_NMI 1
29#define EDAC_OPSTATE_INT 2
30
31extern int edac_op_state;
Dave Jiangc0d12172007-07-19 01:49:46 -070032
Borislav Petkovfee27d72017-02-04 17:42:03 +010033struct bus_type *edac_get_sysfs_subsys(void);
Borislav Petkovbffc7de2017-02-04 18:10:14 +010034int edac_get_report_status(void);
35void edac_set_report_status(int new);
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
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -070043static inline void opstate_init(void)
44{
45 switch (edac_op_state) {
46 case EDAC_OPSTATE_POLL:
47 case EDAC_OPSTATE_NMI:
48 break;
49 default:
50 edac_op_state = EDAC_OPSTATE_POLL;
51 }
52 return;
53}
54
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030055/* Max length of a DIMM label*/
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030056#define EDAC_MC_LABEL_LEN 31
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030057
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030058/* Maximum size of the location string */
Chen, Gong56507692013-10-18 14:30:38 -070059#define LOCATION_SIZE 256
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -030060
61/* Defines the maximum number of labels that can be reported */
62#define EDAC_MAX_LABELS 8
63
64/* String used to join two or more labels */
65#define OTHER_LABEL " or "
66
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -030067/**
68 * enum dev_type - describe the type of memory DRAM chips used at the stick
69 * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it
70 * @DEV_X1: 1 bit for data
71 * @DEV_X2: 2 bits for data
72 * @DEV_X4: 4 bits for data
73 * @DEV_X8: 8 bits for data
74 * @DEV_X16: 16 bits for data
75 * @DEV_X32: 32 bits for data
76 * @DEV_X64: 64 bits for data
77 *
78 * Typical values are x4 and x8.
79 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030080enum dev_type {
81 DEV_UNKNOWN = 0,
82 DEV_X1,
83 DEV_X2,
84 DEV_X4,
85 DEV_X8,
86 DEV_X16,
87 DEV_X32, /* Do these parts exist? */
88 DEV_X64 /* Do these parts exist? */
89};
90
91#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
92#define DEV_FLAG_X1 BIT(DEV_X1)
93#define DEV_FLAG_X2 BIT(DEV_X2)
94#define DEV_FLAG_X4 BIT(DEV_X4)
95#define DEV_FLAG_X8 BIT(DEV_X8)
96#define DEV_FLAG_X16 BIT(DEV_X16)
97#define DEV_FLAG_X32 BIT(DEV_X32)
98#define DEV_FLAG_X64 BIT(DEV_X64)
99
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300100/**
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300101 * enum hw_event_mc_err_type - type of the detected error
102 *
103 * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
104 * corrected error was detected
105 * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that
106 * can't be corrected by ECC, but it is not
107 * fatal (maybe it is on an unused memory area,
108 * or the memory controller could recover from
109 * it for example, by re-trying the operation).
Yazen Ghannam4838a0d2016-12-01 14:24:53 -0600110 * @HW_EVENT_ERR_DEFERRED: Deferred Error - Indicates an uncorrectable
111 * error whose handling is not urgent. This could
112 * be due to hardware data poisoning where the
113 * system can continue operation until the poisoned
114 * data is consumed. Preemptive measures may also
115 * be taken, e.g. offlining pages, etc.
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300116 * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not
117 * be recovered.
Mauro Carvalho Chehabe0020752016-10-28 15:04:52 -0200118 * @HW_EVENT_ERR_INFO: Informational - The CPER spec defines a forth
119 * type of error: informational logs.
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300120 */
121enum hw_event_mc_err_type {
122 HW_EVENT_ERR_CORRECTED,
123 HW_EVENT_ERR_UNCORRECTED,
Yazen Ghannamd12a9692016-11-17 17:57:32 -0500124 HW_EVENT_ERR_DEFERRED,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300125 HW_EVENT_ERR_FATAL,
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300126 HW_EVENT_ERR_INFO,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300127};
128
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300129static inline char *mc_event_error_type(const unsigned int err_type)
130{
131 switch (err_type) {
132 case HW_EVENT_ERR_CORRECTED:
133 return "Corrected";
134 case HW_EVENT_ERR_UNCORRECTED:
135 return "Uncorrected";
Yazen Ghannamd12a9692016-11-17 17:57:32 -0500136 case HW_EVENT_ERR_DEFERRED:
137 return "Deferred";
Mauro Carvalho Chehab8dd93d42013-02-19 21:26:22 -0300138 case HW_EVENT_ERR_FATAL:
139 return "Fatal";
140 default:
141 case HW_EVENT_ERR_INFO:
142 return "Info";
143 }
144}
145
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300146/**
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300147 * enum mem_type - memory types. For a more detailed reference, please see
148 * http://en.wikipedia.org/wiki/DRAM
149 *
Mauro Carvalho Chehabe0020752016-10-28 15:04:52 -0200150 * @MEM_EMPTY: Empty csrow
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300151 * @MEM_RESERVED: Reserved csrow type
152 * @MEM_UNKNOWN: Unknown csrow type
153 * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
154 * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
155 * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
156 * @MEM_SDR: SDR - Single data rate SDRAM
157 * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
158 * They use 3 pins for chip select: Pins 0 and 2 are
159 * for rank 0; pins 1 and 3 are for rank 1, if the memory
160 * is dual-rank.
161 * @MEM_RDR: Registered SDR SDRAM
162 * @MEM_DDR: Double data rate SDRAM
163 * http://en.wikipedia.org/wiki/DDR_SDRAM
164 * @MEM_RDDR: Registered Double data rate SDRAM
165 * This is a variant of the DDR memories.
166 * A registered memory has a buffer inside it, hiding
167 * part of the memory details to the memory controller.
168 * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
169 * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
Alexander Alemayhueca90a32017-01-05 22:11:50 +0100170 * Those memories are labeled as "PC2-" instead of "PC" to
171 * differentiate from DDR.
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300172 * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
173 * and JESD206.
174 * Those memories are accessed per DIMM slot, and not by
175 * a chip select signal.
176 * @MEM_RDDR2: Registered DDR2 RAM
177 * This is a variant of the DDR2 memories.
178 * @MEM_XDR: Rambus XDR
179 * It is an evolution of the original RAMBUS memories,
180 * created to compete with DDR2. Weren't used on any
181 * x86 arch, but cell_edac PPC memory controller uses it.
182 * @MEM_DDR3: DDR3 RAM
183 * @MEM_RDDR3: Registered DDR3 RAM
184 * This is a variant of the DDR3 memories.
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500185 * @MEM_LRDDR3: Load-Reduced DDR3 memory.
Aravind Gopalakrishnan348fec72014-09-18 14:56:58 -0500186 * @MEM_DDR4: Unbuffered DDR4 RAM
Aristeu Rozanski7b827832014-06-18 11:05:01 -0300187 * @MEM_RDDR4: Registered DDR4 RAM
188 * This is a variant of the DDR4 memories.
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500189 * @MEM_LRDDR4: Load-Reduced DDR4 memory.
Tony Luck001f8612018-03-12 11:24:27 -0700190 * @MEM_NVDIMM: Non-volatile RAM
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300191 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300192enum mem_type {
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300193 MEM_EMPTY = 0,
194 MEM_RESERVED,
195 MEM_UNKNOWN,
196 MEM_FPM,
197 MEM_EDO,
198 MEM_BEDO,
199 MEM_SDR,
200 MEM_RDR,
201 MEM_DDR,
202 MEM_RDDR,
203 MEM_RMBS,
204 MEM_DDR2,
205 MEM_FB_DDR2,
206 MEM_RDDR2,
207 MEM_XDR,
208 MEM_DDR3,
209 MEM_RDDR3,
Aravind Gopalakrishnan348fec72014-09-18 14:56:58 -0500210 MEM_LRDDR3,
Aristeu Rozanski7b827832014-06-18 11:05:01 -0300211 MEM_DDR4,
212 MEM_RDDR4,
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500213 MEM_LRDDR4,
Tony Luck001f8612018-03-12 11:24:27 -0700214 MEM_NVDIMM,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300215};
216
217#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
218#define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
219#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
220#define MEM_FLAG_FPM BIT(MEM_FPM)
221#define MEM_FLAG_EDO BIT(MEM_EDO)
222#define MEM_FLAG_BEDO BIT(MEM_BEDO)
223#define MEM_FLAG_SDR BIT(MEM_SDR)
224#define MEM_FLAG_RDR BIT(MEM_RDR)
225#define MEM_FLAG_DDR BIT(MEM_DDR)
226#define MEM_FLAG_RDDR BIT(MEM_RDDR)
227#define MEM_FLAG_RMBS BIT(MEM_RMBS)
228#define MEM_FLAG_DDR2 BIT(MEM_DDR2)
229#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
230#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
231#define MEM_FLAG_XDR BIT(MEM_XDR)
Jim Snow255379a2015-12-03 10:48:51 +0100232#define MEM_FLAG_DDR3 BIT(MEM_DDR3)
233#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
234#define MEM_FLAG_DDR4 BIT(MEM_DDR4)
235#define MEM_FLAG_RDDR4 BIT(MEM_RDDR4)
Yazen Ghannam1e8096b2016-11-17 17:57:28 -0500236#define MEM_FLAG_LRDDR4 BIT(MEM_LRDDR4)
Tony Luck001f8612018-03-12 11:24:27 -0700237#define MEM_FLAG_NVDIMM BIT(MEM_NVDIMM)
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300238
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300239/**
240 * enum edac-type - Error Detection and Correction capabilities and mode
241 * @EDAC_UNKNOWN: Unknown if ECC is available
242 * @EDAC_NONE: Doesn't support ECC
243 * @EDAC_RESERVED: Reserved ECC type
244 * @EDAC_PARITY: Detects parity errors
245 * @EDAC_EC: Error Checking - no correction
246 * @EDAC_SECDED: Single bit error correction, Double detection
247 * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist?
248 * @EDAC_S4ECD4ED: Chipkill x4 devices
249 * @EDAC_S8ECD8ED: Chipkill x8 devices
250 * @EDAC_S16ECD16ED: Chipkill x16 devices
251 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300252enum edac_type {
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300253 EDAC_UNKNOWN = 0,
254 EDAC_NONE,
255 EDAC_RESERVED,
256 EDAC_PARITY,
257 EDAC_EC,
258 EDAC_SECDED,
259 EDAC_S2ECD2ED,
260 EDAC_S4ECD4ED,
261 EDAC_S8ECD8ED,
262 EDAC_S16ECD16ED,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300263};
264
265#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
266#define EDAC_FLAG_NONE BIT(EDAC_NONE)
267#define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
268#define EDAC_FLAG_EC BIT(EDAC_EC)
269#define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
270#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
271#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
272#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
273#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
274
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300275/**
276 * enum scrub_type - scrubbing capabilities
Mauro Carvalho Chehabe0020752016-10-28 15:04:52 -0200277 * @SCRUB_UNKNOWN: Unknown if scrubber is available
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300278 * @SCRUB_NONE: No scrubber
279 * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing
280 * @SCRUB_SW_SRC: Software scrub only errors
281 * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error
282 * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable
283 * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing
284 * @SCRUB_HW_SRC: Hardware scrub only errors
285 * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error
Mauro Carvalho Chehabe0020752016-10-28 15:04:52 -0200286 * @SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300287 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300288enum scrub_type {
Mauro Carvalho Chehabb0610bb82012-03-21 16:21:07 -0300289 SCRUB_UNKNOWN = 0,
290 SCRUB_NONE,
291 SCRUB_SW_PROG,
292 SCRUB_SW_SRC,
293 SCRUB_SW_PROG_SRC,
294 SCRUB_SW_TUNABLE,
295 SCRUB_HW_PROG,
296 SCRUB_HW_SRC,
297 SCRUB_HW_PROG_SRC,
298 SCRUB_HW_TUNABLE
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300299};
300
301#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
302#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
303#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
304#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
305#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
306#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
307#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
308#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
309
310/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
311
312/* EDAC internal operation states */
313#define OP_ALLOC 0x100
314#define OP_RUNNING_POLL 0x201
315#define OP_RUNNING_INTERRUPT 0x202
316#define OP_RUNNING_POLL_INTR 0x203
317#define OP_OFFLINE 0x300
318
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300319/**
320 * enum edac_mc_layer - memory controller hierarchy layer
321 *
322 * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch"
323 * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel"
324 * @EDAC_MC_LAYER_SLOT: memory layer is named "slot"
325 * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select"
Mauro Carvalho Chehabc66b5a72013-02-15 07:21:08 -0300326 * @EDAC_MC_LAYER_ALL_MEM: memory layout is unknown. All memory is mapped
327 * as a single memory area. This is used when
328 * retrieving errors from a firmware driven driver.
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300329 *
330 * This enum is used by the drivers to tell edac_mc_sysfs what name should
331 * be used when describing a memory stick location.
332 */
333enum edac_mc_layer_type {
334 EDAC_MC_LAYER_BRANCH,
335 EDAC_MC_LAYER_CHANNEL,
336 EDAC_MC_LAYER_SLOT,
337 EDAC_MC_LAYER_CHIP_SELECT,
Mauro Carvalho Chehabc66b5a72013-02-15 07:21:08 -0300338 EDAC_MC_LAYER_ALL_MEM,
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300339};
340
341/**
342 * struct edac_mc_layer - describes the memory controller hierarchy
Mauro Carvalho Chehabe0020752016-10-28 15:04:52 -0200343 * @type: layer type
Mauro Carvalho Chehab982216a2012-04-16 13:04:46 -0300344 * @size: number of components per layer. For example,
345 * if the channel layer has two channels, size = 2
346 * @is_virt_csrow: This layer is part of the "csrow" when old API
347 * compatibility mode is enabled. Otherwise, it is
348 * a channel
349 */
350struct edac_mc_layer {
351 enum edac_mc_layer_type type;
352 unsigned size;
353 bool is_virt_csrow;
354};
355
356/*
357 * Maximum number of layers used by the memory controller to uniquely
358 * identify a single memory stick.
359 * NOTE: Changing this constant requires not only to change the constant
360 * below, but also to change the existing code at the core, as there are
361 * some code there that are optimized for 3 layers.
362 */
363#define EDAC_MAX_LAYERS 3
364
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300365struct dimm_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300366 struct device dev;
367
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300368 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300369
370 /* Memory location data */
Robert Richterd55c79a2019-09-02 12:33:41 +0000371 unsigned int location[EDAC_MAX_LAYERS];
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300372
373 struct mem_ctl_info *mci; /* the parent */
Robert Richter977b1ce2019-11-06 09:33:04 +0000374 unsigned int idx; /* index within the parent dimm array */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300375
376 u32 grain; /* granularity of reported error in bytes */
377 enum dev_type dtype; /* memory device type */
378 enum mem_type mtype; /* memory dimm type */
379 enum edac_type edac_mode; /* EDAC mode for this dimm */
380
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300381 u32 nr_pages; /* number of pages on this dimm */
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300382
Robert Richterd55c79a2019-09-02 12:33:41 +0000383 unsigned int csrow, cschannel; /* Points to the old API data */
Fan Wuc798c882018-09-19 01:59:00 +0000384
385 u16 smbios_handle; /* Handle for SMBIOS type 17 */
Robert Richter4aa92c82020-02-17 12:30:23 +0100386
387 u32 ce_count;
388 u32 ue_count;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300389};
390
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300391/**
392 * struct rank_info - contains the information for one DIMM rank
393 *
394 * @chan_idx: channel number where the rank is (typically, 0 or 1)
395 * @ce_count: number of correctable errors for this rank
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300396 * @csrow: A pointer to the chip select row structure (the parent
397 * structure). The location of the rank is given by
398 * the (csrow->csrow_idx, chan_idx) vector.
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300399 * @dimm: A pointer to the DIMM structure, where the DIMM label
400 * information is stored.
401 *
402 * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
403 * This is a bad assumption, but it makes this patch easier. Later
404 * patches in this series will fix this issue.
Mauro Carvalho Chehaba4b4be32012-01-27 10:26:13 -0300405 */
406struct rank_info {
407 int chan_idx;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300408 struct csrow_info *csrow;
409 struct dimm_info *dimm;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300410
411 u32 ce_count; /* Correctable Errors for this csrow */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300412};
413
414struct csrow_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300415 struct device dev;
416
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300417 /* Used only by edac_mc_find_csrow_by_page() */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300418 unsigned long first_page; /* first page number in csrow */
419 unsigned long last_page; /* last page number in csrow */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300420 unsigned long page_mask; /* used for interleaving -
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300421 * 0UL for non intlv */
422
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300423 int csrow_idx; /* the chip-select row */
424
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300425 u32 ue_count; /* Uncorrectable Errors for this csrow */
426 u32 ce_count; /* Correctable Errors for this csrow */
Mauro Carvalho Chehab084a4fc2012-01-27 18:38:08 -0300427
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300428 struct mem_ctl_info *mci; /* the parent */
429
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300430 /* channel information for this csrow */
431 u32 nr_channels;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300432 struct rank_info **channels;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300433};
434
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300435/*
436 * struct errcount_attribute - used to store the several error counts
437 */
438struct errcount_attribute_data {
439 int n_layers;
440 int pos[EDAC_MAX_LAYERS];
441 int layer0, layer1, layer2;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300442};
443
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300444/**
Mauro Carvalho Chehabe0020752016-10-28 15:04:52 -0200445 * struct edac_raw_error_desc - Raw error report structure
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300446 * @grain: minimum granularity for an error report, in bytes
447 * @error_count: number of errors of the same type
Robert Richter672ef0e2020-01-23 09:02:54 +0000448 * @type: severity of the error (CE/UE/Fatal)
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300449 * @top_layer: top layer of the error (layer[0])
450 * @mid_layer: middle layer of the error (layer[1])
451 * @low_layer: low layer of the error (layer[2])
452 * @page_frame_number: page where the error happened
453 * @offset_in_page: page offset
454 * @syndrome: syndrome of the error (or 0 if unknown or if
455 * the syndrome is not applicable)
456 * @msg: error message
457 * @location: location of the error
458 * @label: label of the affected DIMM(s)
459 * @other_detail: other driver-specific detail about the error
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300460 */
461struct edac_raw_error_desc {
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300462 char location[LOCATION_SIZE];
463 char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
464 long grain;
465
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300466 u16 error_count;
Robert Richter672ef0e2020-01-23 09:02:54 +0000467 enum hw_event_mc_err_type type;
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300468 int top_layer;
469 int mid_layer;
470 int low_layer;
471 unsigned long page_frame_number;
472 unsigned long offset_in_page;
473 unsigned long syndrome;
474 const char *msg;
475 const char *other_detail;
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300476};
477
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300478/* MEMORY controller information structure
479 */
480struct mem_ctl_info {
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300481 struct device dev;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200482 struct bus_type *bus;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300483
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300484 struct list_head link; /* for global list of mem_ctl_info structs */
485
486 struct module *owner; /* Module owner of this control struct */
487
488 unsigned long mtype_cap; /* memory types supported by mc */
489 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
490 unsigned long edac_cap; /* configuration capabilities - this is
491 * closely related to edac_ctl_cap. The
492 * difference is that the controller may be
493 * capable of s4ecd4ed which would be listed
494 * in edac_ctl_cap, but if channels aren't
495 * capable of s4ecd4ed then the edac_cap would
496 * not have that capability.
497 */
498 unsigned long scrub_cap; /* chipset scrub capabilities */
499 enum scrub_type scrub_mode; /* current scrub mode */
500
501 /* Translates sdram memory scrub rate given in bytes/sec to the
502 internal representation and configures whatever else needs
503 to be configured.
504 */
505 int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
506
507 /* Get the current sdram memory scrub rate from the internal
508 representation and converts it to the closest matching
509 bandwidth in bytes/sec.
510 */
511 int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
512
513
514 /* pointer to edac checking routine */
515 void (*edac_check) (struct mem_ctl_info * mci);
516
517 /*
518 * Remaps memory pages: controller pages to physical pages.
519 * For most MC's, this will be NULL.
520 */
521 /* FIXME - why not send the phys page to begin with? */
522 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
523 unsigned long page);
524 int mc_idx;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300525 struct csrow_info **csrows;
Robert Richterd55c79a2019-09-02 12:33:41 +0000526 unsigned int nr_csrows, num_cschannel;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300527
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300528 /*
529 * Memory Controller hierarchy
530 *
531 * There are basically two types of memory controller: the ones that
532 * sees memory sticks ("dimms"), and the ones that sees memory ranks.
533 * All old memory controllers enumerate memories per rank, but most
534 * of the recent drivers enumerate memories per DIMM, instead.
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300535 * When the memory controller is per rank, csbased is true.
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300536 */
Robert Richterd55c79a2019-09-02 12:33:41 +0000537 unsigned int n_layers;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300538 struct edac_mc_layer *layers;
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300539 bool csbased;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300540
541 /*
542 * DIMM info. Will eventually remove the entire csrows_info some day
543 */
Robert Richterd55c79a2019-09-02 12:33:41 +0000544 unsigned int tot_dimms;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300545 struct dimm_info **dimms;
Mauro Carvalho Chehaba7d7d2e2012-01-27 14:12:32 -0300546
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300547 /*
548 * FIXME - what about controllers on other busses? - IDs must be
549 * unique. dev pointer should be sufficiently unique, but
550 * BUS:SLOT.FUNC numbers may not be unique.
551 */
Mauro Carvalho Chehabfd687502012-03-16 07:44:18 -0300552 struct device *pdev;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300553 const char *mod_name;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300554 const char *ctl_name;
555 const char *dev_name;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300556 void *pvt_info;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300557 unsigned long start_time; /* mci load start time (in jiffies) */
558
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300559 /*
560 * drivers shouldn't access those fields directly, as the core
561 * already handles that.
562 */
563 u32 ce_noinfo_count, ue_noinfo_count;
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300564 u32 ue_mc, ce_mc;
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300565
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300566 struct completion complete;
567
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300568 /* Additional top controller level attributes, but specified
569 * by the low level driver.
570 *
571 * Set by the low level driver to provide attributes at the
Mauro Carvalho Chehab4275be62012-04-18 15:20:50 -0300572 * controller level.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300573 * An array of structures, NULL terminated
574 *
575 * If attributes are desired, then set to array of attributes
576 * If no attributes are desired, leave NULL
577 */
578 const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
579
580 /* work struct for this MC */
581 struct delayed_work work;
582
Mauro Carvalho Chehabc7ef7642013-02-21 13:36:45 -0300583 /*
584 * Used to report an error - by being at the global struct
585 * makes the memory allocated by the EDAC core
586 */
587 struct edac_raw_error_desc error_desc;
588
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300589 /* the internal state of this controller instance */
590 int op_state;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300591
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300592 struct dentry *debugfs;
593 u8 fake_inject_layer[EDAC_MAX_LAYERS];
Viresh Kumar621a5f72015-09-26 15:04:07 -0700594 bool fake_inject_ue;
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300595 u16 fake_inject_count;
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300596};
Robert Richterbc9ad9e2019-11-06 09:33:02 +0000597
Robert Richterc498afa2019-11-06 09:33:07 +0000598#define mci_for_each_dimm(mci, dimm) \
599 for ((dimm) = (mci)->dimms[0]; \
600 (dimm); \
601 (dimm) = (dimm)->idx + 1 < (mci)->tot_dimms \
602 ? (mci)->dimms[(dimm)->idx + 1] \
603 : NULL)
604
Robert Richterbc9ad9e2019-11-06 09:33:02 +0000605/**
606 * edac_get_dimm_by_index - Get DIMM info at @index from a memory
607 * controller
608 *
609 * @mci: MC descriptor struct mem_ctl_info
610 * @index: index in the memory controller's DIMM array
611 *
612 * Returns a struct dimm_info * or NULL on failure.
613 */
614static inline struct dimm_info *
615edac_get_dimm_by_index(struct mem_ctl_info *mci, int index)
616{
617 if (index < 0 || index >= mci->tot_dimms)
618 return NULL;
619
Robert Richter977b1ce2019-11-06 09:33:04 +0000620 if (WARN_ON_ONCE(mci->dimms[index]->idx != index))
621 return NULL;
622
Robert Richterbc9ad9e2019-11-06 09:33:02 +0000623 return mci->dimms[index];
624}
625
626/**
627 * edac_get_dimm - Get DIMM info from a memory controller given by
628 * [layer0,layer1,layer2] position
629 *
630 * @mci: MC descriptor struct mem_ctl_info
631 * @layer0: layer0 position
632 * @layer1: layer1 position. Unused if n_layers < 2
633 * @layer2: layer2 position. Unused if n_layers < 3
634 *
635 * For 1 layer, this function returns "dimms[layer0]";
636 *
637 * For 2 layers, this function is similar to allocating a two-dimensional
638 * array and returning "dimms[layer0][layer1]";
639 *
640 * For 3 layers, this function is similar to allocating a tri-dimensional
641 * array and returning "dimms[layer0][layer1][layer2]";
642 */
643static inline struct dimm_info *edac_get_dimm(struct mem_ctl_info *mci,
644 int layer0, int layer1, int layer2)
645{
646 int index;
647
648 if (layer0 < 0
649 || (mci->n_layers > 1 && layer1 < 0)
650 || (mci->n_layers > 2 && layer2 < 0))
651 return NULL;
652
653 index = layer0;
654
655 if (mci->n_layers > 1)
656 index = index * mci->layers[1].size + layer1;
657
658 if (mci->n_layers > 2)
659 index = index * mci->layers[2].size + layer2;
660
661 return edac_get_dimm_by_index(mci, index);
662}
663#endif /* _LINUX_EDAC_H_ */