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