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