1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Generic EDAC defs
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Author: Dave Jiang <djiang@mvista.com>
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * 2006-2008 (c) MontaVista Software, Inc. This file is licensed under
7*4882a593Smuzhiyun * the terms of the GNU General Public License version 2. This program
8*4882a593Smuzhiyun * is licensed "as is" without any warranty of any kind, whether express
9*4882a593Smuzhiyun * or implied.
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun #ifndef _LINUX_EDAC_H_
13*4882a593Smuzhiyun #define _LINUX_EDAC_H_
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <linux/atomic.h>
16*4882a593Smuzhiyun #include <linux/device.h>
17*4882a593Smuzhiyun #include <linux/completion.h>
18*4882a593Smuzhiyun #include <linux/workqueue.h>
19*4882a593Smuzhiyun #include <linux/debugfs.h>
20*4882a593Smuzhiyun #include <linux/numa.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #define EDAC_DEVICE_NAME_LEN 31
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun struct device;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #define EDAC_OPSTATE_INVAL -1
27*4882a593Smuzhiyun #define EDAC_OPSTATE_POLL 0
28*4882a593Smuzhiyun #define EDAC_OPSTATE_NMI 1
29*4882a593Smuzhiyun #define EDAC_OPSTATE_INT 2
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun extern int edac_op_state;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun struct bus_type *edac_get_sysfs_subsys(void);
34*4882a593Smuzhiyun
opstate_init(void)35*4882a593Smuzhiyun static inline void opstate_init(void)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun switch (edac_op_state) {
38*4882a593Smuzhiyun case EDAC_OPSTATE_POLL:
39*4882a593Smuzhiyun case EDAC_OPSTATE_NMI:
40*4882a593Smuzhiyun break;
41*4882a593Smuzhiyun default:
42*4882a593Smuzhiyun edac_op_state = EDAC_OPSTATE_POLL;
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun return;
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* Max length of a DIMM label*/
48*4882a593Smuzhiyun #define EDAC_MC_LABEL_LEN 31
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun /* Maximum size of the location string */
51*4882a593Smuzhiyun #define LOCATION_SIZE 256
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* Defines the maximum number of labels that can be reported */
54*4882a593Smuzhiyun #define EDAC_MAX_LABELS 8
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /* String used to join two or more labels */
57*4882a593Smuzhiyun #define OTHER_LABEL " or "
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /**
60*4882a593Smuzhiyun * enum dev_type - describe the type of memory DRAM chips used at the stick
61*4882a593Smuzhiyun * @DEV_UNKNOWN: Can't be determined, or MC doesn't support detect it
62*4882a593Smuzhiyun * @DEV_X1: 1 bit for data
63*4882a593Smuzhiyun * @DEV_X2: 2 bits for data
64*4882a593Smuzhiyun * @DEV_X4: 4 bits for data
65*4882a593Smuzhiyun * @DEV_X8: 8 bits for data
66*4882a593Smuzhiyun * @DEV_X16: 16 bits for data
67*4882a593Smuzhiyun * @DEV_X32: 32 bits for data
68*4882a593Smuzhiyun * @DEV_X64: 64 bits for data
69*4882a593Smuzhiyun *
70*4882a593Smuzhiyun * Typical values are x4 and x8.
71*4882a593Smuzhiyun */
72*4882a593Smuzhiyun enum dev_type {
73*4882a593Smuzhiyun DEV_UNKNOWN = 0,
74*4882a593Smuzhiyun DEV_X1,
75*4882a593Smuzhiyun DEV_X2,
76*4882a593Smuzhiyun DEV_X4,
77*4882a593Smuzhiyun DEV_X8,
78*4882a593Smuzhiyun DEV_X16,
79*4882a593Smuzhiyun DEV_X32, /* Do these parts exist? */
80*4882a593Smuzhiyun DEV_X64 /* Do these parts exist? */
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
84*4882a593Smuzhiyun #define DEV_FLAG_X1 BIT(DEV_X1)
85*4882a593Smuzhiyun #define DEV_FLAG_X2 BIT(DEV_X2)
86*4882a593Smuzhiyun #define DEV_FLAG_X4 BIT(DEV_X4)
87*4882a593Smuzhiyun #define DEV_FLAG_X8 BIT(DEV_X8)
88*4882a593Smuzhiyun #define DEV_FLAG_X16 BIT(DEV_X16)
89*4882a593Smuzhiyun #define DEV_FLAG_X32 BIT(DEV_X32)
90*4882a593Smuzhiyun #define DEV_FLAG_X64 BIT(DEV_X64)
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /**
93*4882a593Smuzhiyun * enum hw_event_mc_err_type - type of the detected error
94*4882a593Smuzhiyun *
95*4882a593Smuzhiyun * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
96*4882a593Smuzhiyun * corrected error was detected
97*4882a593Smuzhiyun * @HW_EVENT_ERR_UNCORRECTED: Uncorrected Error - Indicates an error that
98*4882a593Smuzhiyun * can't be corrected by ECC, but it is not
99*4882a593Smuzhiyun * fatal (maybe it is on an unused memory area,
100*4882a593Smuzhiyun * or the memory controller could recover from
101*4882a593Smuzhiyun * it for example, by re-trying the operation).
102*4882a593Smuzhiyun * @HW_EVENT_ERR_DEFERRED: Deferred Error - Indicates an uncorrectable
103*4882a593Smuzhiyun * error whose handling is not urgent. This could
104*4882a593Smuzhiyun * be due to hardware data poisoning where the
105*4882a593Smuzhiyun * system can continue operation until the poisoned
106*4882a593Smuzhiyun * data is consumed. Preemptive measures may also
107*4882a593Smuzhiyun * be taken, e.g. offlining pages, etc.
108*4882a593Smuzhiyun * @HW_EVENT_ERR_FATAL: Fatal Error - Uncorrected error that could not
109*4882a593Smuzhiyun * be recovered.
110*4882a593Smuzhiyun * @HW_EVENT_ERR_INFO: Informational - The CPER spec defines a forth
111*4882a593Smuzhiyun * type of error: informational logs.
112*4882a593Smuzhiyun */
113*4882a593Smuzhiyun enum hw_event_mc_err_type {
114*4882a593Smuzhiyun HW_EVENT_ERR_CORRECTED,
115*4882a593Smuzhiyun HW_EVENT_ERR_UNCORRECTED,
116*4882a593Smuzhiyun HW_EVENT_ERR_DEFERRED,
117*4882a593Smuzhiyun HW_EVENT_ERR_FATAL,
118*4882a593Smuzhiyun HW_EVENT_ERR_INFO,
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun
mc_event_error_type(const unsigned int err_type)121*4882a593Smuzhiyun static inline char *mc_event_error_type(const unsigned int err_type)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun switch (err_type) {
124*4882a593Smuzhiyun case HW_EVENT_ERR_CORRECTED:
125*4882a593Smuzhiyun return "Corrected";
126*4882a593Smuzhiyun case HW_EVENT_ERR_UNCORRECTED:
127*4882a593Smuzhiyun return "Uncorrected";
128*4882a593Smuzhiyun case HW_EVENT_ERR_DEFERRED:
129*4882a593Smuzhiyun return "Deferred";
130*4882a593Smuzhiyun case HW_EVENT_ERR_FATAL:
131*4882a593Smuzhiyun return "Fatal";
132*4882a593Smuzhiyun default:
133*4882a593Smuzhiyun case HW_EVENT_ERR_INFO:
134*4882a593Smuzhiyun return "Info";
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun * enum mem_type - memory types. For a more detailed reference, please see
140*4882a593Smuzhiyun * http://en.wikipedia.org/wiki/DRAM
141*4882a593Smuzhiyun *
142*4882a593Smuzhiyun * @MEM_EMPTY: Empty csrow
143*4882a593Smuzhiyun * @MEM_RESERVED: Reserved csrow type
144*4882a593Smuzhiyun * @MEM_UNKNOWN: Unknown csrow type
145*4882a593Smuzhiyun * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
146*4882a593Smuzhiyun * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
147*4882a593Smuzhiyun * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
148*4882a593Smuzhiyun * @MEM_SDR: SDR - Single data rate SDRAM
149*4882a593Smuzhiyun * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
150*4882a593Smuzhiyun * They use 3 pins for chip select: Pins 0 and 2 are
151*4882a593Smuzhiyun * for rank 0; pins 1 and 3 are for rank 1, if the memory
152*4882a593Smuzhiyun * is dual-rank.
153*4882a593Smuzhiyun * @MEM_RDR: Registered SDR SDRAM
154*4882a593Smuzhiyun * @MEM_DDR: Double data rate SDRAM
155*4882a593Smuzhiyun * http://en.wikipedia.org/wiki/DDR_SDRAM
156*4882a593Smuzhiyun * @MEM_RDDR: Registered Double data rate SDRAM
157*4882a593Smuzhiyun * This is a variant of the DDR memories.
158*4882a593Smuzhiyun * A registered memory has a buffer inside it, hiding
159*4882a593Smuzhiyun * part of the memory details to the memory controller.
160*4882a593Smuzhiyun * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
161*4882a593Smuzhiyun * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
162*4882a593Smuzhiyun * Those memories are labeled as "PC2-" instead of "PC" to
163*4882a593Smuzhiyun * differentiate from DDR.
164*4882a593Smuzhiyun * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
165*4882a593Smuzhiyun * and JESD206.
166*4882a593Smuzhiyun * Those memories are accessed per DIMM slot, and not by
167*4882a593Smuzhiyun * a chip select signal.
168*4882a593Smuzhiyun * @MEM_RDDR2: Registered DDR2 RAM
169*4882a593Smuzhiyun * This is a variant of the DDR2 memories.
170*4882a593Smuzhiyun * @MEM_XDR: Rambus XDR
171*4882a593Smuzhiyun * It is an evolution of the original RAMBUS memories,
172*4882a593Smuzhiyun * created to compete with DDR2. Weren't used on any
173*4882a593Smuzhiyun * x86 arch, but cell_edac PPC memory controller uses it.
174*4882a593Smuzhiyun * @MEM_DDR3: DDR3 RAM
175*4882a593Smuzhiyun * @MEM_RDDR3: Registered DDR3 RAM
176*4882a593Smuzhiyun * This is a variant of the DDR3 memories.
177*4882a593Smuzhiyun * @MEM_LRDDR3: Load-Reduced DDR3 memory.
178*4882a593Smuzhiyun * @MEM_DDR4: Unbuffered DDR4 RAM
179*4882a593Smuzhiyun * @MEM_RDDR4: Registered DDR4 RAM
180*4882a593Smuzhiyun * This is a variant of the DDR4 memories.
181*4882a593Smuzhiyun * @MEM_LRDDR4: Load-Reduced DDR4 memory.
182*4882a593Smuzhiyun * @MEM_NVDIMM: Non-volatile RAM
183*4882a593Smuzhiyun */
184*4882a593Smuzhiyun enum mem_type {
185*4882a593Smuzhiyun MEM_EMPTY = 0,
186*4882a593Smuzhiyun MEM_RESERVED,
187*4882a593Smuzhiyun MEM_UNKNOWN,
188*4882a593Smuzhiyun MEM_FPM,
189*4882a593Smuzhiyun MEM_EDO,
190*4882a593Smuzhiyun MEM_BEDO,
191*4882a593Smuzhiyun MEM_SDR,
192*4882a593Smuzhiyun MEM_RDR,
193*4882a593Smuzhiyun MEM_DDR,
194*4882a593Smuzhiyun MEM_RDDR,
195*4882a593Smuzhiyun MEM_RMBS,
196*4882a593Smuzhiyun MEM_DDR2,
197*4882a593Smuzhiyun MEM_FB_DDR2,
198*4882a593Smuzhiyun MEM_RDDR2,
199*4882a593Smuzhiyun MEM_XDR,
200*4882a593Smuzhiyun MEM_DDR3,
201*4882a593Smuzhiyun MEM_RDDR3,
202*4882a593Smuzhiyun MEM_LRDDR3,
203*4882a593Smuzhiyun MEM_DDR4,
204*4882a593Smuzhiyun MEM_RDDR4,
205*4882a593Smuzhiyun MEM_LRDDR4,
206*4882a593Smuzhiyun MEM_NVDIMM,
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
210*4882a593Smuzhiyun #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
211*4882a593Smuzhiyun #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
212*4882a593Smuzhiyun #define MEM_FLAG_FPM BIT(MEM_FPM)
213*4882a593Smuzhiyun #define MEM_FLAG_EDO BIT(MEM_EDO)
214*4882a593Smuzhiyun #define MEM_FLAG_BEDO BIT(MEM_BEDO)
215*4882a593Smuzhiyun #define MEM_FLAG_SDR BIT(MEM_SDR)
216*4882a593Smuzhiyun #define MEM_FLAG_RDR BIT(MEM_RDR)
217*4882a593Smuzhiyun #define MEM_FLAG_DDR BIT(MEM_DDR)
218*4882a593Smuzhiyun #define MEM_FLAG_RDDR BIT(MEM_RDDR)
219*4882a593Smuzhiyun #define MEM_FLAG_RMBS BIT(MEM_RMBS)
220*4882a593Smuzhiyun #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
221*4882a593Smuzhiyun #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
222*4882a593Smuzhiyun #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
223*4882a593Smuzhiyun #define MEM_FLAG_XDR BIT(MEM_XDR)
224*4882a593Smuzhiyun #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
225*4882a593Smuzhiyun #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
226*4882a593Smuzhiyun #define MEM_FLAG_DDR4 BIT(MEM_DDR4)
227*4882a593Smuzhiyun #define MEM_FLAG_RDDR4 BIT(MEM_RDDR4)
228*4882a593Smuzhiyun #define MEM_FLAG_LRDDR4 BIT(MEM_LRDDR4)
229*4882a593Smuzhiyun #define MEM_FLAG_NVDIMM BIT(MEM_NVDIMM)
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun /**
232*4882a593Smuzhiyun * enum edac-type - Error Detection and Correction capabilities and mode
233*4882a593Smuzhiyun * @EDAC_UNKNOWN: Unknown if ECC is available
234*4882a593Smuzhiyun * @EDAC_NONE: Doesn't support ECC
235*4882a593Smuzhiyun * @EDAC_RESERVED: Reserved ECC type
236*4882a593Smuzhiyun * @EDAC_PARITY: Detects parity errors
237*4882a593Smuzhiyun * @EDAC_EC: Error Checking - no correction
238*4882a593Smuzhiyun * @EDAC_SECDED: Single bit error correction, Double detection
239*4882a593Smuzhiyun * @EDAC_S2ECD2ED: Chipkill x2 devices - do these exist?
240*4882a593Smuzhiyun * @EDAC_S4ECD4ED: Chipkill x4 devices
241*4882a593Smuzhiyun * @EDAC_S8ECD8ED: Chipkill x8 devices
242*4882a593Smuzhiyun * @EDAC_S16ECD16ED: Chipkill x16 devices
243*4882a593Smuzhiyun */
244*4882a593Smuzhiyun enum edac_type {
245*4882a593Smuzhiyun EDAC_UNKNOWN = 0,
246*4882a593Smuzhiyun EDAC_NONE,
247*4882a593Smuzhiyun EDAC_RESERVED,
248*4882a593Smuzhiyun EDAC_PARITY,
249*4882a593Smuzhiyun EDAC_EC,
250*4882a593Smuzhiyun EDAC_SECDED,
251*4882a593Smuzhiyun EDAC_S2ECD2ED,
252*4882a593Smuzhiyun EDAC_S4ECD4ED,
253*4882a593Smuzhiyun EDAC_S8ECD8ED,
254*4882a593Smuzhiyun EDAC_S16ECD16ED,
255*4882a593Smuzhiyun };
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
258*4882a593Smuzhiyun #define EDAC_FLAG_NONE BIT(EDAC_NONE)
259*4882a593Smuzhiyun #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
260*4882a593Smuzhiyun #define EDAC_FLAG_EC BIT(EDAC_EC)
261*4882a593Smuzhiyun #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
262*4882a593Smuzhiyun #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
263*4882a593Smuzhiyun #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
264*4882a593Smuzhiyun #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
265*4882a593Smuzhiyun #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun /**
268*4882a593Smuzhiyun * enum scrub_type - scrubbing capabilities
269*4882a593Smuzhiyun * @SCRUB_UNKNOWN: Unknown if scrubber is available
270*4882a593Smuzhiyun * @SCRUB_NONE: No scrubber
271*4882a593Smuzhiyun * @SCRUB_SW_PROG: SW progressive (sequential) scrubbing
272*4882a593Smuzhiyun * @SCRUB_SW_SRC: Software scrub only errors
273*4882a593Smuzhiyun * @SCRUB_SW_PROG_SRC: Progressive software scrub from an error
274*4882a593Smuzhiyun * @SCRUB_SW_TUNABLE: Software scrub frequency is tunable
275*4882a593Smuzhiyun * @SCRUB_HW_PROG: HW progressive (sequential) scrubbing
276*4882a593Smuzhiyun * @SCRUB_HW_SRC: Hardware scrub only errors
277*4882a593Smuzhiyun * @SCRUB_HW_PROG_SRC: Progressive hardware scrub from an error
278*4882a593Smuzhiyun * @SCRUB_HW_TUNABLE: Hardware scrub frequency is tunable
279*4882a593Smuzhiyun */
280*4882a593Smuzhiyun enum scrub_type {
281*4882a593Smuzhiyun SCRUB_UNKNOWN = 0,
282*4882a593Smuzhiyun SCRUB_NONE,
283*4882a593Smuzhiyun SCRUB_SW_PROG,
284*4882a593Smuzhiyun SCRUB_SW_SRC,
285*4882a593Smuzhiyun SCRUB_SW_PROG_SRC,
286*4882a593Smuzhiyun SCRUB_SW_TUNABLE,
287*4882a593Smuzhiyun SCRUB_HW_PROG,
288*4882a593Smuzhiyun SCRUB_HW_SRC,
289*4882a593Smuzhiyun SCRUB_HW_PROG_SRC,
290*4882a593Smuzhiyun SCRUB_HW_TUNABLE
291*4882a593Smuzhiyun };
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
294*4882a593Smuzhiyun #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
295*4882a593Smuzhiyun #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
296*4882a593Smuzhiyun #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
297*4882a593Smuzhiyun #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
298*4882a593Smuzhiyun #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
299*4882a593Smuzhiyun #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
300*4882a593Smuzhiyun #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun /* EDAC internal operation states */
305*4882a593Smuzhiyun #define OP_ALLOC 0x100
306*4882a593Smuzhiyun #define OP_RUNNING_POLL 0x201
307*4882a593Smuzhiyun #define OP_RUNNING_INTERRUPT 0x202
308*4882a593Smuzhiyun #define OP_RUNNING_POLL_INTR 0x203
309*4882a593Smuzhiyun #define OP_OFFLINE 0x300
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun /**
312*4882a593Smuzhiyun * enum edac_mc_layer - memory controller hierarchy layer
313*4882a593Smuzhiyun *
314*4882a593Smuzhiyun * @EDAC_MC_LAYER_BRANCH: memory layer is named "branch"
315*4882a593Smuzhiyun * @EDAC_MC_LAYER_CHANNEL: memory layer is named "channel"
316*4882a593Smuzhiyun * @EDAC_MC_LAYER_SLOT: memory layer is named "slot"
317*4882a593Smuzhiyun * @EDAC_MC_LAYER_CHIP_SELECT: memory layer is named "chip select"
318*4882a593Smuzhiyun * @EDAC_MC_LAYER_ALL_MEM: memory layout is unknown. All memory is mapped
319*4882a593Smuzhiyun * as a single memory area. This is used when
320*4882a593Smuzhiyun * retrieving errors from a firmware driven driver.
321*4882a593Smuzhiyun *
322*4882a593Smuzhiyun * This enum is used by the drivers to tell edac_mc_sysfs what name should
323*4882a593Smuzhiyun * be used when describing a memory stick location.
324*4882a593Smuzhiyun */
325*4882a593Smuzhiyun enum edac_mc_layer_type {
326*4882a593Smuzhiyun EDAC_MC_LAYER_BRANCH,
327*4882a593Smuzhiyun EDAC_MC_LAYER_CHANNEL,
328*4882a593Smuzhiyun EDAC_MC_LAYER_SLOT,
329*4882a593Smuzhiyun EDAC_MC_LAYER_CHIP_SELECT,
330*4882a593Smuzhiyun EDAC_MC_LAYER_ALL_MEM,
331*4882a593Smuzhiyun };
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun /**
334*4882a593Smuzhiyun * struct edac_mc_layer - describes the memory controller hierarchy
335*4882a593Smuzhiyun * @type: layer type
336*4882a593Smuzhiyun * @size: number of components per layer. For example,
337*4882a593Smuzhiyun * if the channel layer has two channels, size = 2
338*4882a593Smuzhiyun * @is_virt_csrow: This layer is part of the "csrow" when old API
339*4882a593Smuzhiyun * compatibility mode is enabled. Otherwise, it is
340*4882a593Smuzhiyun * a channel
341*4882a593Smuzhiyun */
342*4882a593Smuzhiyun struct edac_mc_layer {
343*4882a593Smuzhiyun enum edac_mc_layer_type type;
344*4882a593Smuzhiyun unsigned size;
345*4882a593Smuzhiyun bool is_virt_csrow;
346*4882a593Smuzhiyun };
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun /*
349*4882a593Smuzhiyun * Maximum number of layers used by the memory controller to uniquely
350*4882a593Smuzhiyun * identify a single memory stick.
351*4882a593Smuzhiyun * NOTE: Changing this constant requires not only to change the constant
352*4882a593Smuzhiyun * below, but also to change the existing code at the core, as there are
353*4882a593Smuzhiyun * some code there that are optimized for 3 layers.
354*4882a593Smuzhiyun */
355*4882a593Smuzhiyun #define EDAC_MAX_LAYERS 3
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun struct dimm_info {
358*4882a593Smuzhiyun struct device dev;
359*4882a593Smuzhiyun
360*4882a593Smuzhiyun char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun /* Memory location data */
363*4882a593Smuzhiyun unsigned int location[EDAC_MAX_LAYERS];
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun struct mem_ctl_info *mci; /* the parent */
366*4882a593Smuzhiyun unsigned int idx; /* index within the parent dimm array */
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun u32 grain; /* granularity of reported error in bytes */
369*4882a593Smuzhiyun enum dev_type dtype; /* memory device type */
370*4882a593Smuzhiyun enum mem_type mtype; /* memory dimm type */
371*4882a593Smuzhiyun enum edac_type edac_mode; /* EDAC mode for this dimm */
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun u32 nr_pages; /* number of pages on this dimm */
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun unsigned int csrow, cschannel; /* Points to the old API data */
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun u16 smbios_handle; /* Handle for SMBIOS type 17 */
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun u32 ce_count;
380*4882a593Smuzhiyun u32 ue_count;
381*4882a593Smuzhiyun };
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun /**
384*4882a593Smuzhiyun * struct rank_info - contains the information for one DIMM rank
385*4882a593Smuzhiyun *
386*4882a593Smuzhiyun * @chan_idx: channel number where the rank is (typically, 0 or 1)
387*4882a593Smuzhiyun * @ce_count: number of correctable errors for this rank
388*4882a593Smuzhiyun * @csrow: A pointer to the chip select row structure (the parent
389*4882a593Smuzhiyun * structure). The location of the rank is given by
390*4882a593Smuzhiyun * the (csrow->csrow_idx, chan_idx) vector.
391*4882a593Smuzhiyun * @dimm: A pointer to the DIMM structure, where the DIMM label
392*4882a593Smuzhiyun * information is stored.
393*4882a593Smuzhiyun *
394*4882a593Smuzhiyun * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
395*4882a593Smuzhiyun * This is a bad assumption, but it makes this patch easier. Later
396*4882a593Smuzhiyun * patches in this series will fix this issue.
397*4882a593Smuzhiyun */
398*4882a593Smuzhiyun struct rank_info {
399*4882a593Smuzhiyun int chan_idx;
400*4882a593Smuzhiyun struct csrow_info *csrow;
401*4882a593Smuzhiyun struct dimm_info *dimm;
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun u32 ce_count; /* Correctable Errors for this csrow */
404*4882a593Smuzhiyun };
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun struct csrow_info {
407*4882a593Smuzhiyun struct device dev;
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun /* Used only by edac_mc_find_csrow_by_page() */
410*4882a593Smuzhiyun unsigned long first_page; /* first page number in csrow */
411*4882a593Smuzhiyun unsigned long last_page; /* last page number in csrow */
412*4882a593Smuzhiyun unsigned long page_mask; /* used for interleaving -
413*4882a593Smuzhiyun * 0UL for non intlv */
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun int csrow_idx; /* the chip-select row */
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun u32 ue_count; /* Uncorrectable Errors for this csrow */
418*4882a593Smuzhiyun u32 ce_count; /* Correctable Errors for this csrow */
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun struct mem_ctl_info *mci; /* the parent */
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun /* channel information for this csrow */
423*4882a593Smuzhiyun u32 nr_channels;
424*4882a593Smuzhiyun struct rank_info **channels;
425*4882a593Smuzhiyun };
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun /*
428*4882a593Smuzhiyun * struct errcount_attribute - used to store the several error counts
429*4882a593Smuzhiyun */
430*4882a593Smuzhiyun struct errcount_attribute_data {
431*4882a593Smuzhiyun int n_layers;
432*4882a593Smuzhiyun int pos[EDAC_MAX_LAYERS];
433*4882a593Smuzhiyun int layer0, layer1, layer2;
434*4882a593Smuzhiyun };
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /**
437*4882a593Smuzhiyun * struct edac_raw_error_desc - Raw error report structure
438*4882a593Smuzhiyun * @grain: minimum granularity for an error report, in bytes
439*4882a593Smuzhiyun * @error_count: number of errors of the same type
440*4882a593Smuzhiyun * @type: severity of the error (CE/UE/Fatal)
441*4882a593Smuzhiyun * @top_layer: top layer of the error (layer[0])
442*4882a593Smuzhiyun * @mid_layer: middle layer of the error (layer[1])
443*4882a593Smuzhiyun * @low_layer: low layer of the error (layer[2])
444*4882a593Smuzhiyun * @page_frame_number: page where the error happened
445*4882a593Smuzhiyun * @offset_in_page: page offset
446*4882a593Smuzhiyun * @syndrome: syndrome of the error (or 0 if unknown or if
447*4882a593Smuzhiyun * the syndrome is not applicable)
448*4882a593Smuzhiyun * @msg: error message
449*4882a593Smuzhiyun * @location: location of the error
450*4882a593Smuzhiyun * @label: label of the affected DIMM(s)
451*4882a593Smuzhiyun * @other_detail: other driver-specific detail about the error
452*4882a593Smuzhiyun */
453*4882a593Smuzhiyun struct edac_raw_error_desc {
454*4882a593Smuzhiyun char location[LOCATION_SIZE];
455*4882a593Smuzhiyun char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
456*4882a593Smuzhiyun long grain;
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun u16 error_count;
459*4882a593Smuzhiyun enum hw_event_mc_err_type type;
460*4882a593Smuzhiyun int top_layer;
461*4882a593Smuzhiyun int mid_layer;
462*4882a593Smuzhiyun int low_layer;
463*4882a593Smuzhiyun unsigned long page_frame_number;
464*4882a593Smuzhiyun unsigned long offset_in_page;
465*4882a593Smuzhiyun unsigned long syndrome;
466*4882a593Smuzhiyun const char *msg;
467*4882a593Smuzhiyun const char *other_detail;
468*4882a593Smuzhiyun };
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun /* MEMORY controller information structure
471*4882a593Smuzhiyun */
472*4882a593Smuzhiyun struct mem_ctl_info {
473*4882a593Smuzhiyun struct device dev;
474*4882a593Smuzhiyun struct bus_type *bus;
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun struct list_head link; /* for global list of mem_ctl_info structs */
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun struct module *owner; /* Module owner of this control struct */
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun unsigned long mtype_cap; /* memory types supported by mc */
481*4882a593Smuzhiyun unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
482*4882a593Smuzhiyun unsigned long edac_cap; /* configuration capabilities - this is
483*4882a593Smuzhiyun * closely related to edac_ctl_cap. The
484*4882a593Smuzhiyun * difference is that the controller may be
485*4882a593Smuzhiyun * capable of s4ecd4ed which would be listed
486*4882a593Smuzhiyun * in edac_ctl_cap, but if channels aren't
487*4882a593Smuzhiyun * capable of s4ecd4ed then the edac_cap would
488*4882a593Smuzhiyun * not have that capability.
489*4882a593Smuzhiyun */
490*4882a593Smuzhiyun unsigned long scrub_cap; /* chipset scrub capabilities */
491*4882a593Smuzhiyun enum scrub_type scrub_mode; /* current scrub mode */
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun /* Translates sdram memory scrub rate given in bytes/sec to the
494*4882a593Smuzhiyun internal representation and configures whatever else needs
495*4882a593Smuzhiyun to be configured.
496*4882a593Smuzhiyun */
497*4882a593Smuzhiyun int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun /* Get the current sdram memory scrub rate from the internal
500*4882a593Smuzhiyun representation and converts it to the closest matching
501*4882a593Smuzhiyun bandwidth in bytes/sec.
502*4882a593Smuzhiyun */
503*4882a593Smuzhiyun int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun /* pointer to edac checking routine */
507*4882a593Smuzhiyun void (*edac_check) (struct mem_ctl_info * mci);
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun /*
510*4882a593Smuzhiyun * Remaps memory pages: controller pages to physical pages.
511*4882a593Smuzhiyun * For most MC's, this will be NULL.
512*4882a593Smuzhiyun */
513*4882a593Smuzhiyun /* FIXME - why not send the phys page to begin with? */
514*4882a593Smuzhiyun unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
515*4882a593Smuzhiyun unsigned long page);
516*4882a593Smuzhiyun int mc_idx;
517*4882a593Smuzhiyun struct csrow_info **csrows;
518*4882a593Smuzhiyun unsigned int nr_csrows, num_cschannel;
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun /*
521*4882a593Smuzhiyun * Memory Controller hierarchy
522*4882a593Smuzhiyun *
523*4882a593Smuzhiyun * There are basically two types of memory controller: the ones that
524*4882a593Smuzhiyun * sees memory sticks ("dimms"), and the ones that sees memory ranks.
525*4882a593Smuzhiyun * All old memory controllers enumerate memories per rank, but most
526*4882a593Smuzhiyun * of the recent drivers enumerate memories per DIMM, instead.
527*4882a593Smuzhiyun * When the memory controller is per rank, csbased is true.
528*4882a593Smuzhiyun */
529*4882a593Smuzhiyun unsigned int n_layers;
530*4882a593Smuzhiyun struct edac_mc_layer *layers;
531*4882a593Smuzhiyun bool csbased;
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun /*
534*4882a593Smuzhiyun * DIMM info. Will eventually remove the entire csrows_info some day
535*4882a593Smuzhiyun */
536*4882a593Smuzhiyun unsigned int tot_dimms;
537*4882a593Smuzhiyun struct dimm_info **dimms;
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun /*
540*4882a593Smuzhiyun * FIXME - what about controllers on other busses? - IDs must be
541*4882a593Smuzhiyun * unique. dev pointer should be sufficiently unique, but
542*4882a593Smuzhiyun * BUS:SLOT.FUNC numbers may not be unique.
543*4882a593Smuzhiyun */
544*4882a593Smuzhiyun struct device *pdev;
545*4882a593Smuzhiyun const char *mod_name;
546*4882a593Smuzhiyun const char *ctl_name;
547*4882a593Smuzhiyun const char *dev_name;
548*4882a593Smuzhiyun void *pvt_info;
549*4882a593Smuzhiyun unsigned long start_time; /* mci load start time (in jiffies) */
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun /*
552*4882a593Smuzhiyun * drivers shouldn't access those fields directly, as the core
553*4882a593Smuzhiyun * already handles that.
554*4882a593Smuzhiyun */
555*4882a593Smuzhiyun u32 ce_noinfo_count, ue_noinfo_count;
556*4882a593Smuzhiyun u32 ue_mc, ce_mc;
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun struct completion complete;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun /* Additional top controller level attributes, but specified
561*4882a593Smuzhiyun * by the low level driver.
562*4882a593Smuzhiyun *
563*4882a593Smuzhiyun * Set by the low level driver to provide attributes at the
564*4882a593Smuzhiyun * controller level.
565*4882a593Smuzhiyun * An array of structures, NULL terminated
566*4882a593Smuzhiyun *
567*4882a593Smuzhiyun * If attributes are desired, then set to array of attributes
568*4882a593Smuzhiyun * If no attributes are desired, leave NULL
569*4882a593Smuzhiyun */
570*4882a593Smuzhiyun const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun /* work struct for this MC */
573*4882a593Smuzhiyun struct delayed_work work;
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun /*
576*4882a593Smuzhiyun * Used to report an error - by being at the global struct
577*4882a593Smuzhiyun * makes the memory allocated by the EDAC core
578*4882a593Smuzhiyun */
579*4882a593Smuzhiyun struct edac_raw_error_desc error_desc;
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun /* the internal state of this controller instance */
582*4882a593Smuzhiyun int op_state;
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun struct dentry *debugfs;
585*4882a593Smuzhiyun u8 fake_inject_layer[EDAC_MAX_LAYERS];
586*4882a593Smuzhiyun bool fake_inject_ue;
587*4882a593Smuzhiyun u16 fake_inject_count;
588*4882a593Smuzhiyun };
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun #define mci_for_each_dimm(mci, dimm) \
591*4882a593Smuzhiyun for ((dimm) = (mci)->dimms[0]; \
592*4882a593Smuzhiyun (dimm); \
593*4882a593Smuzhiyun (dimm) = (dimm)->idx + 1 < (mci)->tot_dimms \
594*4882a593Smuzhiyun ? (mci)->dimms[(dimm)->idx + 1] \
595*4882a593Smuzhiyun : NULL)
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun /**
598*4882a593Smuzhiyun * edac_get_dimm - Get DIMM info from a memory controller given by
599*4882a593Smuzhiyun * [layer0,layer1,layer2] position
600*4882a593Smuzhiyun *
601*4882a593Smuzhiyun * @mci: MC descriptor struct mem_ctl_info
602*4882a593Smuzhiyun * @layer0: layer0 position
603*4882a593Smuzhiyun * @layer1: layer1 position. Unused if n_layers < 2
604*4882a593Smuzhiyun * @layer2: layer2 position. Unused if n_layers < 3
605*4882a593Smuzhiyun *
606*4882a593Smuzhiyun * For 1 layer, this function returns "dimms[layer0]";
607*4882a593Smuzhiyun *
608*4882a593Smuzhiyun * For 2 layers, this function is similar to allocating a two-dimensional
609*4882a593Smuzhiyun * array and returning "dimms[layer0][layer1]";
610*4882a593Smuzhiyun *
611*4882a593Smuzhiyun * For 3 layers, this function is similar to allocating a tri-dimensional
612*4882a593Smuzhiyun * array and returning "dimms[layer0][layer1][layer2]";
613*4882a593Smuzhiyun */
edac_get_dimm(struct mem_ctl_info * mci,int layer0,int layer1,int layer2)614*4882a593Smuzhiyun static inline struct dimm_info *edac_get_dimm(struct mem_ctl_info *mci,
615*4882a593Smuzhiyun int layer0, int layer1, int layer2)
616*4882a593Smuzhiyun {
617*4882a593Smuzhiyun int index;
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun if (layer0 < 0
620*4882a593Smuzhiyun || (mci->n_layers > 1 && layer1 < 0)
621*4882a593Smuzhiyun || (mci->n_layers > 2 && layer2 < 0))
622*4882a593Smuzhiyun return NULL;
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun index = layer0;
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun if (mci->n_layers > 1)
627*4882a593Smuzhiyun index = index * mci->layers[1].size + layer1;
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun if (mci->n_layers > 2)
630*4882a593Smuzhiyun index = index * mci->layers[2].size + layer2;
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun if (index < 0 || index >= mci->tot_dimms)
633*4882a593Smuzhiyun return NULL;
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun if (WARN_ON_ONCE(mci->dimms[index]->idx != index))
636*4882a593Smuzhiyun return NULL;
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun return mci->dimms[index];
639*4882a593Smuzhiyun }
640*4882a593Smuzhiyun #endif /* _LINUX_EDAC_H_ */
641