Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Generic EDAC defs
0003  *
0004  * Author: Dave Jiang <djiang@mvista.com>
0005  *
0006  * 2006-2008 (c) MontaVista Software, Inc. This file is licensed under
0007  * the terms of the GNU General Public License version 2. This program
0008  * is licensed "as is" without any warranty of any kind, whether express
0009  * or implied.
0010  *
0011  */
0012 #ifndef _LINUX_EDAC_H_
0013 #define _LINUX_EDAC_H_
0014 
0015 #include <linux/atomic.h>
0016 #include <linux/device.h>
0017 #include <linux/completion.h>
0018 #include <linux/workqueue.h>
0019 #include <linux/debugfs.h>
0020 #include <linux/numa.h>
0021 
0022 #define EDAC_DEVICE_NAME_LEN    31
0023 
0024 struct device;
0025 
0026 #define EDAC_OPSTATE_INVAL  -1
0027 #define EDAC_OPSTATE_POLL   0
0028 #define EDAC_OPSTATE_NMI    1
0029 #define EDAC_OPSTATE_INT    2
0030 
0031 extern int edac_op_state;
0032 
0033 struct bus_type *edac_get_sysfs_subsys(void);
0034 
0035 static inline void opstate_init(void)
0036 {
0037     switch (edac_op_state) {
0038     case EDAC_OPSTATE_POLL:
0039     case EDAC_OPSTATE_NMI:
0040         break;
0041     default:
0042         edac_op_state = EDAC_OPSTATE_POLL;
0043     }
0044     return;
0045 }
0046 
0047 /* Max length of a DIMM label*/
0048 #define EDAC_MC_LABEL_LEN   31
0049 
0050 /* Maximum size of the location string */
0051 #define LOCATION_SIZE 256
0052 
0053 /* Defines the maximum number of labels that can be reported */
0054 #define EDAC_MAX_LABELS     8
0055 
0056 /* String used to join two or more labels */
0057 #define OTHER_LABEL " or "
0058 
0059 /**
0060  * enum dev_type - describe the type of memory DRAM chips used at the stick
0061  * @DEV_UNKNOWN:    Can't be determined, or MC doesn't support detect it
0062  * @DEV_X1:     1 bit for data
0063  * @DEV_X2:     2 bits for data
0064  * @DEV_X4:     4 bits for data
0065  * @DEV_X8:     8 bits for data
0066  * @DEV_X16:        16 bits for data
0067  * @DEV_X32:        32 bits for data
0068  * @DEV_X64:        64 bits for data
0069  *
0070  * Typical values are x4 and x8.
0071  */
0072 enum dev_type {
0073     DEV_UNKNOWN = 0,
0074     DEV_X1,
0075     DEV_X2,
0076     DEV_X4,
0077     DEV_X8,
0078     DEV_X16,
0079     DEV_X32,        /* Do these parts exist? */
0080     DEV_X64         /* Do these parts exist? */
0081 };
0082 
0083 #define DEV_FLAG_UNKNOWN    BIT(DEV_UNKNOWN)
0084 #define DEV_FLAG_X1     BIT(DEV_X1)
0085 #define DEV_FLAG_X2     BIT(DEV_X2)
0086 #define DEV_FLAG_X4     BIT(DEV_X4)
0087 #define DEV_FLAG_X8     BIT(DEV_X8)
0088 #define DEV_FLAG_X16        BIT(DEV_X16)
0089 #define DEV_FLAG_X32        BIT(DEV_X32)
0090 #define DEV_FLAG_X64        BIT(DEV_X64)
0091 
0092 /**
0093  * enum hw_event_mc_err_type - type of the detected error
0094  *
0095  * @HW_EVENT_ERR_CORRECTED: Corrected Error - Indicates that an ECC
0096  *              corrected error was detected
0097  * @HW_EVENT_ERR_UNCORRECTED:   Uncorrected Error - Indicates an error that
0098  *              can't be corrected by ECC, but it is not
0099  *              fatal (maybe it is on an unused memory area,
0100  *              or the memory controller could recover from
0101  *              it for example, by re-trying the operation).
0102  * @HW_EVENT_ERR_DEFERRED:  Deferred Error - Indicates an uncorrectable
0103  *              error whose handling is not urgent. This could
0104  *              be due to hardware data poisoning where the
0105  *              system can continue operation until the poisoned
0106  *              data is consumed. Preemptive measures may also
0107  *              be taken, e.g. offlining pages, etc.
0108  * @HW_EVENT_ERR_FATAL:     Fatal Error - Uncorrected error that could not
0109  *              be recovered.
0110  * @HW_EVENT_ERR_INFO:      Informational - The CPER spec defines a forth
0111  *              type of error: informational logs.
0112  */
0113 enum hw_event_mc_err_type {
0114     HW_EVENT_ERR_CORRECTED,
0115     HW_EVENT_ERR_UNCORRECTED,
0116     HW_EVENT_ERR_DEFERRED,
0117     HW_EVENT_ERR_FATAL,
0118     HW_EVENT_ERR_INFO,
0119 };
0120 
0121 static inline char *mc_event_error_type(const unsigned int err_type)
0122 {
0123     switch (err_type) {
0124     case HW_EVENT_ERR_CORRECTED:
0125         return "Corrected";
0126     case HW_EVENT_ERR_UNCORRECTED:
0127         return "Uncorrected";
0128     case HW_EVENT_ERR_DEFERRED:
0129         return "Deferred";
0130     case HW_EVENT_ERR_FATAL:
0131         return "Fatal";
0132     default:
0133     case HW_EVENT_ERR_INFO:
0134         return "Info";
0135     }
0136 }
0137 
0138 /**
0139  * enum mem_type - memory types. For a more detailed reference, please see
0140  *          http://en.wikipedia.org/wiki/DRAM
0141  *
0142  * @MEM_EMPTY:      Empty csrow
0143  * @MEM_RESERVED:   Reserved csrow type
0144  * @MEM_UNKNOWN:    Unknown csrow type
0145  * @MEM_FPM:        FPM - Fast Page Mode, used on systems up to 1995.
0146  * @MEM_EDO:        EDO - Extended data out, used on systems up to 1998.
0147  * @MEM_BEDO:       BEDO - Burst Extended data out, an EDO variant.
0148  * @MEM_SDR:        SDR - Single data rate SDRAM
0149  *          http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
0150  *          They use 3 pins for chip select: Pins 0 and 2 are
0151  *          for rank 0; pins 1 and 3 are for rank 1, if the memory
0152  *          is dual-rank.
0153  * @MEM_RDR:        Registered SDR SDRAM
0154  * @MEM_DDR:        Double data rate SDRAM
0155  *          http://en.wikipedia.org/wiki/DDR_SDRAM
0156  * @MEM_RDDR:       Registered Double data rate SDRAM
0157  *          This is a variant of the DDR memories.
0158  *          A registered memory has a buffer inside it, hiding
0159  *          part of the memory details to the memory controller.
0160  * @MEM_RMBS:       Rambus DRAM, used on a few Pentium III/IV controllers.
0161  * @MEM_DDR2:       DDR2 RAM, as described at JEDEC JESD79-2F.
0162  *          Those memories are labeled as "PC2-" instead of "PC" to
0163  *          differentiate from DDR.
0164  * @MEM_FB_DDR2:    Fully-Buffered DDR2, as described at JEDEC Std No. 205
0165  *          and JESD206.
0166  *          Those memories are accessed per DIMM slot, and not by
0167  *          a chip select signal.
0168  * @MEM_RDDR2:      Registered DDR2 RAM
0169  *          This is a variant of the DDR2 memories.
0170  * @MEM_XDR:        Rambus XDR
0171  *          It is an evolution of the original RAMBUS memories,
0172  *          created to compete with DDR2. Weren't used on any
0173  *          x86 arch, but cell_edac PPC memory controller uses it.
0174  * @MEM_DDR3:       DDR3 RAM
0175  * @MEM_RDDR3:      Registered DDR3 RAM
0176  *          This is a variant of the DDR3 memories.
0177  * @MEM_LRDDR3:     Load-Reduced DDR3 memory.
0178  * @MEM_LPDDR3:     Low-Power DDR3 memory.
0179  * @MEM_DDR4:       Unbuffered DDR4 RAM
0180  * @MEM_RDDR4:      Registered DDR4 RAM
0181  *          This is a variant of the DDR4 memories.
0182  * @MEM_LRDDR4:     Load-Reduced DDR4 memory.
0183  * @MEM_LPDDR4:     Low-Power DDR4 memory.
0184  * @MEM_DDR5:       Unbuffered DDR5 RAM
0185  * @MEM_RDDR5:      Registered DDR5 RAM
0186  * @MEM_LRDDR5:     Load-Reduced DDR5 memory.
0187  * @MEM_NVDIMM:     Non-volatile RAM
0188  * @MEM_WIO2:       Wide I/O 2.
0189  * @MEM_HBM2:       High bandwidth Memory Gen 2.
0190  */
0191 enum mem_type {
0192     MEM_EMPTY = 0,
0193     MEM_RESERVED,
0194     MEM_UNKNOWN,
0195     MEM_FPM,
0196     MEM_EDO,
0197     MEM_BEDO,
0198     MEM_SDR,
0199     MEM_RDR,
0200     MEM_DDR,
0201     MEM_RDDR,
0202     MEM_RMBS,
0203     MEM_DDR2,
0204     MEM_FB_DDR2,
0205     MEM_RDDR2,
0206     MEM_XDR,
0207     MEM_DDR3,
0208     MEM_RDDR3,
0209     MEM_LRDDR3,
0210     MEM_LPDDR3,
0211     MEM_DDR4,
0212     MEM_RDDR4,
0213     MEM_LRDDR4,
0214     MEM_LPDDR4,
0215     MEM_DDR5,
0216     MEM_RDDR5,
0217     MEM_LRDDR5,
0218     MEM_NVDIMM,
0219     MEM_WIO2,
0220     MEM_HBM2,
0221 };
0222 
0223 #define MEM_FLAG_EMPTY      BIT(MEM_EMPTY)
0224 #define MEM_FLAG_RESERVED   BIT(MEM_RESERVED)
0225 #define MEM_FLAG_UNKNOWN    BIT(MEM_UNKNOWN)
0226 #define MEM_FLAG_FPM        BIT(MEM_FPM)
0227 #define MEM_FLAG_EDO        BIT(MEM_EDO)
0228 #define MEM_FLAG_BEDO       BIT(MEM_BEDO)
0229 #define MEM_FLAG_SDR        BIT(MEM_SDR)
0230 #define MEM_FLAG_RDR        BIT(MEM_RDR)
0231 #define MEM_FLAG_DDR        BIT(MEM_DDR)
0232 #define MEM_FLAG_RDDR       BIT(MEM_RDDR)
0233 #define MEM_FLAG_RMBS       BIT(MEM_RMBS)
0234 #define MEM_FLAG_DDR2           BIT(MEM_DDR2)
0235 #define MEM_FLAG_FB_DDR2        BIT(MEM_FB_DDR2)
0236 #define MEM_FLAG_RDDR2          BIT(MEM_RDDR2)
0237 #define MEM_FLAG_XDR            BIT(MEM_XDR)
0238 #define MEM_FLAG_DDR3           BIT(MEM_DDR3)
0239 #define MEM_FLAG_RDDR3          BIT(MEM_RDDR3)
0240 #define MEM_FLAG_LPDDR3         BIT(MEM_LPDDR3)
0241 #define MEM_FLAG_DDR4           BIT(MEM_DDR4)
0242 #define MEM_FLAG_RDDR4          BIT(MEM_RDDR4)
0243 #define MEM_FLAG_LRDDR4         BIT(MEM_LRDDR4)
0244 #define MEM_FLAG_LPDDR4         BIT(MEM_LPDDR4)
0245 #define MEM_FLAG_DDR5           BIT(MEM_DDR5)
0246 #define MEM_FLAG_RDDR5          BIT(MEM_RDDR5)
0247 #define MEM_FLAG_LRDDR5         BIT(MEM_LRDDR5)
0248 #define MEM_FLAG_NVDIMM         BIT(MEM_NVDIMM)
0249 #define MEM_FLAG_WIO2       BIT(MEM_WIO2)
0250 #define MEM_FLAG_HBM2       BIT(MEM_HBM2)
0251 
0252 /**
0253  * enum edac_type - Error Detection and Correction capabilities and mode
0254  * @EDAC_UNKNOWN:   Unknown if ECC is available
0255  * @EDAC_NONE:      Doesn't support ECC
0256  * @EDAC_RESERVED:  Reserved ECC type
0257  * @EDAC_PARITY:    Detects parity errors
0258  * @EDAC_EC:        Error Checking - no correction
0259  * @EDAC_SECDED:    Single bit error correction, Double detection
0260  * @EDAC_S2ECD2ED:  Chipkill x2 devices - do these exist?
0261  * @EDAC_S4ECD4ED:  Chipkill x4 devices
0262  * @EDAC_S8ECD8ED:  Chipkill x8 devices
0263  * @EDAC_S16ECD16ED:    Chipkill x16 devices
0264  */
0265 enum edac_type {
0266     EDAC_UNKNOWN =  0,
0267     EDAC_NONE,
0268     EDAC_RESERVED,
0269     EDAC_PARITY,
0270     EDAC_EC,
0271     EDAC_SECDED,
0272     EDAC_S2ECD2ED,
0273     EDAC_S4ECD4ED,
0274     EDAC_S8ECD8ED,
0275     EDAC_S16ECD16ED,
0276 };
0277 
0278 #define EDAC_FLAG_UNKNOWN   BIT(EDAC_UNKNOWN)
0279 #define EDAC_FLAG_NONE      BIT(EDAC_NONE)
0280 #define EDAC_FLAG_PARITY    BIT(EDAC_PARITY)
0281 #define EDAC_FLAG_EC        BIT(EDAC_EC)
0282 #define EDAC_FLAG_SECDED    BIT(EDAC_SECDED)
0283 #define EDAC_FLAG_S2ECD2ED  BIT(EDAC_S2ECD2ED)
0284 #define EDAC_FLAG_S4ECD4ED  BIT(EDAC_S4ECD4ED)
0285 #define EDAC_FLAG_S8ECD8ED  BIT(EDAC_S8ECD8ED)
0286 #define EDAC_FLAG_S16ECD16ED    BIT(EDAC_S16ECD16ED)
0287 
0288 /**
0289  * enum scrub_type - scrubbing capabilities
0290  * @SCRUB_UNKNOWN:      Unknown if scrubber is available
0291  * @SCRUB_NONE:         No scrubber
0292  * @SCRUB_SW_PROG:      SW progressive (sequential) scrubbing
0293  * @SCRUB_SW_SRC:       Software scrub only errors
0294  * @SCRUB_SW_PROG_SRC:      Progressive software scrub from an error
0295  * @SCRUB_SW_TUNABLE:       Software scrub frequency is tunable
0296  * @SCRUB_HW_PROG:      HW progressive (sequential) scrubbing
0297  * @SCRUB_HW_SRC:       Hardware scrub only errors
0298  * @SCRUB_HW_PROG_SRC:      Progressive hardware scrub from an error
0299  * @SCRUB_HW_TUNABLE:       Hardware scrub frequency is tunable
0300  */
0301 enum scrub_type {
0302     SCRUB_UNKNOWN = 0,
0303     SCRUB_NONE,
0304     SCRUB_SW_PROG,
0305     SCRUB_SW_SRC,
0306     SCRUB_SW_PROG_SRC,
0307     SCRUB_SW_TUNABLE,
0308     SCRUB_HW_PROG,
0309     SCRUB_HW_SRC,
0310     SCRUB_HW_PROG_SRC,
0311     SCRUB_HW_TUNABLE
0312 };
0313 
0314 #define SCRUB_FLAG_SW_PROG  BIT(SCRUB_SW_PROG)
0315 #define SCRUB_FLAG_SW_SRC   BIT(SCRUB_SW_SRC)
0316 #define SCRUB_FLAG_SW_PROG_SRC  BIT(SCRUB_SW_PROG_SRC)
0317 #define SCRUB_FLAG_SW_TUN   BIT(SCRUB_SW_SCRUB_TUNABLE)
0318 #define SCRUB_FLAG_HW_PROG  BIT(SCRUB_HW_PROG)
0319 #define SCRUB_FLAG_HW_SRC   BIT(SCRUB_HW_SRC)
0320 #define SCRUB_FLAG_HW_PROG_SRC  BIT(SCRUB_HW_PROG_SRC)
0321 #define SCRUB_FLAG_HW_TUN   BIT(SCRUB_HW_TUNABLE)
0322 
0323 /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
0324 
0325 /* EDAC internal operation states */
0326 #define OP_ALLOC        0x100
0327 #define OP_RUNNING_POLL     0x201
0328 #define OP_RUNNING_INTERRUPT    0x202
0329 #define OP_RUNNING_POLL_INTR    0x203
0330 #define OP_OFFLINE      0x300
0331 
0332 /**
0333  * enum edac_mc_layer_type - memory controller hierarchy layer
0334  *
0335  * @EDAC_MC_LAYER_BRANCH:   memory layer is named "branch"
0336  * @EDAC_MC_LAYER_CHANNEL:  memory layer is named "channel"
0337  * @EDAC_MC_LAYER_SLOT:     memory layer is named "slot"
0338  * @EDAC_MC_LAYER_CHIP_SELECT:  memory layer is named "chip select"
0339  * @EDAC_MC_LAYER_ALL_MEM:  memory layout is unknown. All memory is mapped
0340  *              as a single memory area. This is used when
0341  *              retrieving errors from a firmware driven driver.
0342  *
0343  * This enum is used by the drivers to tell edac_mc_sysfs what name should
0344  * be used when describing a memory stick location.
0345  */
0346 enum edac_mc_layer_type {
0347     EDAC_MC_LAYER_BRANCH,
0348     EDAC_MC_LAYER_CHANNEL,
0349     EDAC_MC_LAYER_SLOT,
0350     EDAC_MC_LAYER_CHIP_SELECT,
0351     EDAC_MC_LAYER_ALL_MEM,
0352 };
0353 
0354 /**
0355  * struct edac_mc_layer - describes the memory controller hierarchy
0356  * @type:       layer type
0357  * @size:       number of components per layer. For example,
0358  *          if the channel layer has two channels, size = 2
0359  * @is_virt_csrow:  This layer is part of the "csrow" when old API
0360  *          compatibility mode is enabled. Otherwise, it is
0361  *          a channel
0362  */
0363 struct edac_mc_layer {
0364     enum edac_mc_layer_type type;
0365     unsigned        size;
0366     bool            is_virt_csrow;
0367 };
0368 
0369 /*
0370  * Maximum number of layers used by the memory controller to uniquely
0371  * identify a single memory stick.
0372  * NOTE: Changing this constant requires not only to change the constant
0373  * below, but also to change the existing code at the core, as there are
0374  * some code there that are optimized for 3 layers.
0375  */
0376 #define EDAC_MAX_LAYERS     3
0377 
0378 struct dimm_info {
0379     struct device dev;
0380 
0381     char label[EDAC_MC_LABEL_LEN + 1];  /* DIMM label on motherboard */
0382 
0383     /* Memory location data */
0384     unsigned int location[EDAC_MAX_LAYERS];
0385 
0386     struct mem_ctl_info *mci;   /* the parent */
0387     unsigned int idx;       /* index within the parent dimm array */
0388 
0389     u32 grain;      /* granularity of reported error in bytes */
0390     enum dev_type dtype;    /* memory device type */
0391     enum mem_type mtype;    /* memory dimm type */
0392     enum edac_type edac_mode;   /* EDAC mode for this dimm */
0393 
0394     u32 nr_pages;           /* number of pages on this dimm */
0395 
0396     unsigned int csrow, cschannel;  /* Points to the old API data */
0397 
0398     u16 smbios_handle;              /* Handle for SMBIOS type 17 */
0399 
0400     u32 ce_count;
0401     u32 ue_count;
0402 };
0403 
0404 /**
0405  * struct rank_info - contains the information for one DIMM rank
0406  *
0407  * @chan_idx:   channel number where the rank is (typically, 0 or 1)
0408  * @ce_count:   number of correctable errors for this rank
0409  * @csrow:  A pointer to the chip select row structure (the parent
0410  *      structure). The location of the rank is given by
0411  *      the (csrow->csrow_idx, chan_idx) vector.
0412  * @dimm:   A pointer to the DIMM structure, where the DIMM label
0413  *      information is stored.
0414  *
0415  * FIXME: Currently, the EDAC core model will assume one DIMM per rank.
0416  *    This is a bad assumption, but it makes this patch easier. Later
0417  *    patches in this series will fix this issue.
0418  */
0419 struct rank_info {
0420     int chan_idx;
0421     struct csrow_info *csrow;
0422     struct dimm_info *dimm;
0423 
0424     u32 ce_count;       /* Correctable Errors for this csrow */
0425 };
0426 
0427 struct csrow_info {
0428     struct device dev;
0429 
0430     /* Used only by edac_mc_find_csrow_by_page() */
0431     unsigned long first_page;   /* first page number in csrow */
0432     unsigned long last_page;    /* last page number in csrow */
0433     unsigned long page_mask;    /* used for interleaving -
0434                      * 0UL for non intlv */
0435 
0436     int csrow_idx;          /* the chip-select row */
0437 
0438     u32 ue_count;       /* Uncorrectable Errors for this csrow */
0439     u32 ce_count;       /* Correctable Errors for this csrow */
0440 
0441     struct mem_ctl_info *mci;   /* the parent */
0442 
0443     /* channel information for this csrow */
0444     u32 nr_channels;
0445     struct rank_info **channels;
0446 };
0447 
0448 /*
0449  * struct errcount_attribute - used to store the several error counts
0450  */
0451 struct errcount_attribute_data {
0452     int n_layers;
0453     int pos[EDAC_MAX_LAYERS];
0454     int layer0, layer1, layer2;
0455 };
0456 
0457 /**
0458  * struct edac_raw_error_desc - Raw error report structure
0459  * @grain:          minimum granularity for an error report, in bytes
0460  * @error_count:        number of errors of the same type
0461  * @type:           severity of the error (CE/UE/Fatal)
0462  * @top_layer:          top layer of the error (layer[0])
0463  * @mid_layer:          middle layer of the error (layer[1])
0464  * @low_layer:          low layer of the error (layer[2])
0465  * @page_frame_number:      page where the error happened
0466  * @offset_in_page:     page offset
0467  * @syndrome:           syndrome of the error (or 0 if unknown or if
0468  *              the syndrome is not applicable)
0469  * @msg:            error message
0470  * @location:           location of the error
0471  * @label:          label of the affected DIMM(s)
0472  * @other_detail:       other driver-specific detail about the error
0473  */
0474 struct edac_raw_error_desc {
0475     char location[LOCATION_SIZE];
0476     char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * EDAC_MAX_LABELS];
0477     long grain;
0478 
0479     u16 error_count;
0480     enum hw_event_mc_err_type type;
0481     int top_layer;
0482     int mid_layer;
0483     int low_layer;
0484     unsigned long page_frame_number;
0485     unsigned long offset_in_page;
0486     unsigned long syndrome;
0487     const char *msg;
0488     const char *other_detail;
0489 };
0490 
0491 /* MEMORY controller information structure
0492  */
0493 struct mem_ctl_info {
0494     struct device           dev;
0495     struct bus_type         *bus;
0496 
0497     struct list_head link;  /* for global list of mem_ctl_info structs */
0498 
0499     struct module *owner;   /* Module owner of this control struct */
0500 
0501     unsigned long mtype_cap;    /* memory types supported by mc */
0502     unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
0503     unsigned long edac_cap; /* configuration capabilities - this is
0504                  * closely related to edac_ctl_cap.  The
0505                  * difference is that the controller may be
0506                  * capable of s4ecd4ed which would be listed
0507                  * in edac_ctl_cap, but if channels aren't
0508                  * capable of s4ecd4ed then the edac_cap would
0509                  * not have that capability.
0510                  */
0511     unsigned long scrub_cap;    /* chipset scrub capabilities */
0512     enum scrub_type scrub_mode; /* current scrub mode */
0513 
0514     /* Translates sdram memory scrub rate given in bytes/sec to the
0515        internal representation and configures whatever else needs
0516        to be configured.
0517      */
0518     int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
0519 
0520     /* Get the current sdram memory scrub rate from the internal
0521        representation and converts it to the closest matching
0522        bandwidth in bytes/sec.
0523      */
0524     int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
0525 
0526 
0527     /* pointer to edac checking routine */
0528     void (*edac_check) (struct mem_ctl_info * mci);
0529 
0530     /*
0531      * Remaps memory pages: controller pages to physical pages.
0532      * For most MC's, this will be NULL.
0533      */
0534     /* FIXME - why not send the phys page to begin with? */
0535     unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
0536                        unsigned long page);
0537     int mc_idx;
0538     struct csrow_info **csrows;
0539     unsigned int nr_csrows, num_cschannel;
0540 
0541     /*
0542      * Memory Controller hierarchy
0543      *
0544      * There are basically two types of memory controller: the ones that
0545      * sees memory sticks ("dimms"), and the ones that sees memory ranks.
0546      * All old memory controllers enumerate memories per rank, but most
0547      * of the recent drivers enumerate memories per DIMM, instead.
0548      * When the memory controller is per rank, csbased is true.
0549      */
0550     unsigned int n_layers;
0551     struct edac_mc_layer *layers;
0552     bool csbased;
0553 
0554     /*
0555      * DIMM info. Will eventually remove the entire csrows_info some day
0556      */
0557     unsigned int tot_dimms;
0558     struct dimm_info **dimms;
0559 
0560     /*
0561      * FIXME - what about controllers on other busses? - IDs must be
0562      * unique.  dev pointer should be sufficiently unique, but
0563      * BUS:SLOT.FUNC numbers may not be unique.
0564      */
0565     struct device *pdev;
0566     const char *mod_name;
0567     const char *ctl_name;
0568     const char *dev_name;
0569     void *pvt_info;
0570     unsigned long start_time;   /* mci load start time (in jiffies) */
0571 
0572     /*
0573      * drivers shouldn't access those fields directly, as the core
0574      * already handles that.
0575      */
0576     u32 ce_noinfo_count, ue_noinfo_count;
0577     u32 ue_mc, ce_mc;
0578 
0579     struct completion complete;
0580 
0581     /* Additional top controller level attributes, but specified
0582      * by the low level driver.
0583      *
0584      * Set by the low level driver to provide attributes at the
0585      * controller level.
0586      * An array of structures, NULL terminated
0587      *
0588      * If attributes are desired, then set to array of attributes
0589      * If no attributes are desired, leave NULL
0590      */
0591     const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
0592 
0593     /* work struct for this MC */
0594     struct delayed_work work;
0595 
0596     /*
0597      * Used to report an error - by being at the global struct
0598      * makes the memory allocated by the EDAC core
0599      */
0600     struct edac_raw_error_desc error_desc;
0601 
0602     /* the internal state of this controller instance */
0603     int op_state;
0604 
0605     struct dentry *debugfs;
0606     u8 fake_inject_layer[EDAC_MAX_LAYERS];
0607     bool fake_inject_ue;
0608     u16 fake_inject_count;
0609 };
0610 
0611 #define mci_for_each_dimm(mci, dimm)                \
0612     for ((dimm) = (mci)->dimms[0];              \
0613          (dimm);                        \
0614          (dimm) = (dimm)->idx + 1 < (mci)->tot_dimms    \
0615              ? (mci)->dimms[(dimm)->idx + 1]        \
0616              : NULL)
0617 
0618 /**
0619  * edac_get_dimm - Get DIMM info from a memory controller given by
0620  *                 [layer0,layer1,layer2] position
0621  *
0622  * @mci:    MC descriptor struct mem_ctl_info
0623  * @layer0: layer0 position
0624  * @layer1: layer1 position. Unused if n_layers < 2
0625  * @layer2: layer2 position. Unused if n_layers < 3
0626  *
0627  * For 1 layer, this function returns "dimms[layer0]";
0628  *
0629  * For 2 layers, this function is similar to allocating a two-dimensional
0630  * array and returning "dimms[layer0][layer1]";
0631  *
0632  * For 3 layers, this function is similar to allocating a tri-dimensional
0633  * array and returning "dimms[layer0][layer1][layer2]";
0634  */
0635 static inline struct dimm_info *edac_get_dimm(struct mem_ctl_info *mci,
0636     int layer0, int layer1, int layer2)
0637 {
0638     int index;
0639 
0640     if (layer0 < 0
0641         || (mci->n_layers > 1 && layer1 < 0)
0642         || (mci->n_layers > 2 && layer2 < 0))
0643         return NULL;
0644 
0645     index = layer0;
0646 
0647     if (mci->n_layers > 1)
0648         index = index * mci->layers[1].size + layer1;
0649 
0650     if (mci->n_layers > 2)
0651         index = index * mci->layers[2].size + layer2;
0652 
0653     if (index < 0 || index >= mci->tot_dimms)
0654         return NULL;
0655 
0656     if (WARN_ON_ONCE(mci->dimms[index]->idx != index))
0657         return NULL;
0658 
0659     return mci->dimms[index];
0660 }
0661 #endif /* _LINUX_EDAC_H_ */