blob: 0714d67a6e1a27471443c8bb9d9faa23c68c280e [file] [log] [blame]
Dave Jiangc0d12172007-07-19 01:49:46 -07001/*
2 * Generic EDAC defs
3 *
4 * Author: Dave Jiang <djiang@mvista.com>
5 *
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -07006 * 2006-2008 (c) MontaVista Software, Inc. This file is licensed under
Dave Jiangc0d12172007-07-19 01:49:46 -07007 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 *
11 */
12#ifndef _LINUX_EDAC_H_
13#define _LINUX_EDAC_H_
14
Arun Sharma600634972011-07-26 16:09:06 -070015#include <linux/atomic.h>
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080016#include <linux/device.h>
Dave Jiangc0d12172007-07-19 01:49:46 -070017
18#define EDAC_OPSTATE_INVAL -1
19#define EDAC_OPSTATE_POLL 0
20#define EDAC_OPSTATE_NMI 1
21#define EDAC_OPSTATE_INT 2
22
23extern int edac_op_state;
Dave Jiang66ee2f92007-07-19 01:49:54 -070024extern int edac_err_assert;
Dave Jiangc0d12172007-07-19 01:49:46 -070025extern atomic_t edac_handlers;
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080026extern struct bus_type edac_subsys;
Dave Jiangc0d12172007-07-19 01:49:46 -070027
28extern int edac_handler_set(void);
29extern void edac_atomic_assert_error(void);
Kay Sieversfe5ff8b2011-12-14 15:21:07 -080030extern struct bus_type *edac_get_sysfs_subsys(void);
31extern void edac_put_sysfs_subsys(void);
Dave Jiangc0d12172007-07-19 01:49:46 -070032
Hitoshi Mitakec3c52bc2008-04-29 01:03:18 -070033static inline void opstate_init(void)
34{
35 switch (edac_op_state) {
36 case EDAC_OPSTATE_POLL:
37 case EDAC_OPSTATE_NMI:
38 break;
39 default:
40 edac_op_state = EDAC_OPSTATE_POLL;
41 }
42 return;
43}
44
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -030045#define EDAC_MC_LABEL_LEN 31
46#define MC_PROC_NAME_MAX_LEN 7
47
48/* memory devices */
49enum dev_type {
50 DEV_UNKNOWN = 0,
51 DEV_X1,
52 DEV_X2,
53 DEV_X4,
54 DEV_X8,
55 DEV_X16,
56 DEV_X32, /* Do these parts exist? */
57 DEV_X64 /* Do these parts exist? */
58};
59
60#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
61#define DEV_FLAG_X1 BIT(DEV_X1)
62#define DEV_FLAG_X2 BIT(DEV_X2)
63#define DEV_FLAG_X4 BIT(DEV_X4)
64#define DEV_FLAG_X8 BIT(DEV_X8)
65#define DEV_FLAG_X16 BIT(DEV_X16)
66#define DEV_FLAG_X32 BIT(DEV_X32)
67#define DEV_FLAG_X64 BIT(DEV_X64)
68
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -030069/**
70 * enum mem_type - memory types. For a more detailed reference, please see
71 * http://en.wikipedia.org/wiki/DRAM
72 *
73 * @MEM_EMPTY Empty csrow
74 * @MEM_RESERVED: Reserved csrow type
75 * @MEM_UNKNOWN: Unknown csrow type
76 * @MEM_FPM: FPM - Fast Page Mode, used on systems up to 1995.
77 * @MEM_EDO: EDO - Extended data out, used on systems up to 1998.
78 * @MEM_BEDO: BEDO - Burst Extended data out, an EDO variant.
79 * @MEM_SDR: SDR - Single data rate SDRAM
80 * http://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory
81 * They use 3 pins for chip select: Pins 0 and 2 are
82 * for rank 0; pins 1 and 3 are for rank 1, if the memory
83 * is dual-rank.
84 * @MEM_RDR: Registered SDR SDRAM
85 * @MEM_DDR: Double data rate SDRAM
86 * http://en.wikipedia.org/wiki/DDR_SDRAM
87 * @MEM_RDDR: Registered Double data rate SDRAM
88 * This is a variant of the DDR memories.
89 * A registered memory has a buffer inside it, hiding
90 * part of the memory details to the memory controller.
91 * @MEM_RMBS: Rambus DRAM, used on a few Pentium III/IV controllers.
92 * @MEM_DDR2: DDR2 RAM, as described at JEDEC JESD79-2F.
93 * Those memories are labed as "PC2-" instead of "PC" to
94 * differenciate from DDR.
95 * @MEM_FB_DDR2: Fully-Buffered DDR2, as described at JEDEC Std No. 205
96 * and JESD206.
97 * Those memories are accessed per DIMM slot, and not by
98 * a chip select signal.
99 * @MEM_RDDR2: Registered DDR2 RAM
100 * This is a variant of the DDR2 memories.
101 * @MEM_XDR: Rambus XDR
102 * It is an evolution of the original RAMBUS memories,
103 * created to compete with DDR2. Weren't used on any
104 * x86 arch, but cell_edac PPC memory controller uses it.
105 * @MEM_DDR3: DDR3 RAM
106 * @MEM_RDDR3: Registered DDR3 RAM
107 * This is a variant of the DDR3 memories.
108 */
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300109enum mem_type {
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300110 MEM_EMPTY = 0,
111 MEM_RESERVED,
112 MEM_UNKNOWN,
113 MEM_FPM,
114 MEM_EDO,
115 MEM_BEDO,
116 MEM_SDR,
117 MEM_RDR,
118 MEM_DDR,
119 MEM_RDDR,
120 MEM_RMBS,
121 MEM_DDR2,
122 MEM_FB_DDR2,
123 MEM_RDDR2,
124 MEM_XDR,
125 MEM_DDR3,
126 MEM_RDDR3,
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300127};
128
129#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
130#define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
131#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
132#define MEM_FLAG_FPM BIT(MEM_FPM)
133#define MEM_FLAG_EDO BIT(MEM_EDO)
134#define MEM_FLAG_BEDO BIT(MEM_BEDO)
135#define MEM_FLAG_SDR BIT(MEM_SDR)
136#define MEM_FLAG_RDR BIT(MEM_RDR)
137#define MEM_FLAG_DDR BIT(MEM_DDR)
138#define MEM_FLAG_RDDR BIT(MEM_RDDR)
139#define MEM_FLAG_RMBS BIT(MEM_RMBS)
140#define MEM_FLAG_DDR2 BIT(MEM_DDR2)
141#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
142#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
143#define MEM_FLAG_XDR BIT(MEM_XDR)
144#define MEM_FLAG_DDR3 BIT(MEM_DDR3)
145#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
146
147/* chipset Error Detection and Correction capabilities and mode */
148enum edac_type {
149 EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
150 EDAC_NONE, /* Doesn't support ECC */
151 EDAC_RESERVED, /* Reserved ECC type */
152 EDAC_PARITY, /* Detects parity errors */
153 EDAC_EC, /* Error Checking - no correction */
154 EDAC_SECDED, /* Single bit error correction, Double detection */
155 EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
156 EDAC_S4ECD4ED, /* Chipkill x4 devices */
157 EDAC_S8ECD8ED, /* Chipkill x8 devices */
158 EDAC_S16ECD16ED, /* Chipkill x16 devices */
159};
160
161#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
162#define EDAC_FLAG_NONE BIT(EDAC_NONE)
163#define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
164#define EDAC_FLAG_EC BIT(EDAC_EC)
165#define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
166#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
167#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
168#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
169#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
170
171/* scrubbing capabilities */
172enum scrub_type {
173 SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
174 SCRUB_NONE, /* No scrubber */
175 SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
176 SCRUB_SW_SRC, /* Software scrub only errors */
177 SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
178 SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
179 SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
180 SCRUB_HW_SRC, /* Hardware scrub only errors */
181 SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
182 SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
183};
184
185#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
186#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
187#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
188#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
189#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
190#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
191#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
192#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
193
194/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
195
196/* EDAC internal operation states */
197#define OP_ALLOC 0x100
198#define OP_RUNNING_POLL 0x201
199#define OP_RUNNING_INTERRUPT 0x202
200#define OP_RUNNING_POLL_INTR 0x203
201#define OP_OFFLINE 0x300
202
203/*
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300204 * Concepts used at the EDAC subsystem
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300205 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300206 * There are several things to be aware of that aren't at all obvious:
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300207 *
208 * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
209 *
210 * These are some of the many terms that are thrown about that don't always
211 * mean what people think they mean (Inconceivable!). In the interest of
212 * creating a common ground for discussion, terms and their definitions
213 * will be established.
214 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300215 * Memory devices: The individual DRAM chips on a memory stick. These
216 * devices commonly output 4 and 8 bits each (x4, x8).
217 * Grouping several of these in parallel provides the
218 * number of bits that the memory controller expects:
219 * typically 72 bits, in order to provide 64 bits +
220 * 8 bits of ECC data.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300221 *
222 * Memory Stick: A printed circuit board that aggregates multiple
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300223 * memory devices in parallel. In general, this is the
224 * Field Replaceable Unit (FRU) which gets replaced, in
225 * the case of excessive errors. Most often it is also
226 * called DIMM (Dual Inline Memory Module).
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300227 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300228 * Memory Socket: A physical connector on the motherboard that accepts
229 * a single memory stick. Also called as "slot" on several
230 * datasheets.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300231 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300232 * Channel: A memory controller channel, responsible to communicate
233 * with a group of DIMMs. Each channel has its own
234 * independent control (command) and data bus, and can
235 * be used independently or grouped with other channels.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300236 *
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300237 * Branch: It is typically the highest hierarchy on a
238 * Fully-Buffered DIMM memory controller.
239 * Typically, it contains two channels.
240 * Two channels at the same branch can be used in single
241 * mode or in lockstep mode.
242 * When lockstep is enabled, the cacheline is doubled,
243 * but it generally brings some performance penalty.
244 * Also, it is generally not possible to point to just one
245 * memory stick when an error occurs, as the error
246 * correction code is calculated using two DIMMs instead
247 * of one. Due to that, it is capable of correcting more
248 * errors than on single mode.
249 *
250 * Single-channel: The data accessed by the memory controller is contained
251 * into one dimm only. E. g. if the data is 64 bits-wide,
252 * the data flows to the CPU using one 64 bits parallel
253 * access.
254 * Typically used with SDR, DDR, DDR2 and DDR3 memories.
255 * FB-DIMM and RAMBUS use a different concept for channel,
256 * so this concept doesn't apply there.
257 *
258 * Double-channel: The data size accessed by the memory controller is
259 * interlaced into two dimms, accessed at the same time.
260 * E. g. if the DIMM is 64 bits-wide (72 bits with ECC),
261 * the data flows to the CPU using a 128 bits parallel
262 * access.
263 *
264 * Chip-select row: This is the name of the DRAM signal used to select the
265 * DRAM ranks to be accessed. Common chip-select rows for
266 * single channel are 64 bits, for dual channel 128 bits.
267 * It may not be visible by the memory controller, as some
268 * DIMM types have a memory buffer that can hide direct
269 * access to it from the Memory Controller.
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300270 *
271 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
272 * Motherboards commonly drive two chip-select pins to
273 * a memory stick. A single-ranked stick, will occupy
274 * only one of those rows. The other will be unused.
275 *
276 * Double-Ranked stick: A double-ranked stick has two chip-select rows which
277 * access different sets of memory devices. The two
278 * rows cannot be accessed concurrently.
279 *
280 * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
281 * A double-sided stick has two chip-select rows which
Mauro Carvalho Chehab01a6e282012-02-03 13:17:48 -0300282 * access different sets of memory devices. The two
283 * rows cannot be accessed concurrently. "Double-sided"
Mauro Carvalho Chehabddeb3542011-03-04 15:11:29 -0300284 * is irrespective of the memory devices being mounted
285 * on both sides of the memory stick.
286 *
287 * Socket set: All of the memory sticks that are required for
288 * a single memory access or all of the memory sticks
289 * spanned by a chip-select row. A single socket set
290 * has two chip-select rows and if double-sided sticks
291 * are used these will occupy those chip-select rows.
292 *
293 * Bank: This term is avoided because it is unclear when
294 * needing to distinguish between chip-select rows and
295 * socket sets.
296 *
297 * Controller pages:
298 *
299 * Physical pages:
300 *
301 * Virtual pages:
302 *
303 *
304 * STRUCTURE ORGANIZATION AND CHOICES
305 *
306 *
307 *
308 * PS - I enjoyed writing all that about as much as you enjoyed reading it.
309 */
310
311struct channel_info {
312 int chan_idx; /* channel index */
313 u32 ce_count; /* Correctable Errors for this CHANNEL */
314 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
315 struct csrow_info *csrow; /* the parent */
316};
317
318struct csrow_info {
319 unsigned long first_page; /* first page number in dimm */
320 unsigned long last_page; /* last page number in dimm */
321 unsigned long page_mask; /* used for interleaving -
322 * 0UL for non intlv
323 */
324 u32 nr_pages; /* number of pages in csrow */
325 u32 grain; /* granularity of reported error in bytes */
326 int csrow_idx; /* the chip-select row */
327 enum dev_type dtype; /* memory device type */
328 u32 ue_count; /* Uncorrectable Errors for this csrow */
329 u32 ce_count; /* Correctable Errors for this csrow */
330 enum mem_type mtype; /* memory csrow type */
331 enum edac_type edac_mode; /* EDAC mode for this csrow */
332 struct mem_ctl_info *mci; /* the parent */
333
334 struct kobject kobj; /* sysfs kobject for this csrow */
335
336 /* channel information for this csrow */
337 u32 nr_channels;
338 struct channel_info *channels;
339};
340
341struct mcidev_sysfs_group {
342 const char *name; /* group name */
343 const struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */
344};
345
346struct mcidev_sysfs_group_kobj {
347 struct list_head list; /* list for all instances within a mc */
348
349 struct kobject kobj; /* kobj for the group */
350
351 const struct mcidev_sysfs_group *grp; /* group description table */
352 struct mem_ctl_info *mci; /* the parent */
353};
354
355/* mcidev_sysfs_attribute structure
356 * used for driver sysfs attributes and in mem_ctl_info
357 * sysfs top level entries
358 */
359struct mcidev_sysfs_attribute {
360 /* It should use either attr or grp */
361 struct attribute attr;
362 const struct mcidev_sysfs_group *grp; /* Points to a group of attributes */
363
364 /* Ops for show/store values at the attribute - not used on group */
365 ssize_t (*show)(struct mem_ctl_info *,char *);
366 ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
367};
368
369/* MEMORY controller information structure
370 */
371struct mem_ctl_info {
372 struct list_head link; /* for global list of mem_ctl_info structs */
373
374 struct module *owner; /* Module owner of this control struct */
375
376 unsigned long mtype_cap; /* memory types supported by mc */
377 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
378 unsigned long edac_cap; /* configuration capabilities - this is
379 * closely related to edac_ctl_cap. The
380 * difference is that the controller may be
381 * capable of s4ecd4ed which would be listed
382 * in edac_ctl_cap, but if channels aren't
383 * capable of s4ecd4ed then the edac_cap would
384 * not have that capability.
385 */
386 unsigned long scrub_cap; /* chipset scrub capabilities */
387 enum scrub_type scrub_mode; /* current scrub mode */
388
389 /* Translates sdram memory scrub rate given in bytes/sec to the
390 internal representation and configures whatever else needs
391 to be configured.
392 */
393 int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
394
395 /* Get the current sdram memory scrub rate from the internal
396 representation and converts it to the closest matching
397 bandwidth in bytes/sec.
398 */
399 int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
400
401
402 /* pointer to edac checking routine */
403 void (*edac_check) (struct mem_ctl_info * mci);
404
405 /*
406 * Remaps memory pages: controller pages to physical pages.
407 * For most MC's, this will be NULL.
408 */
409 /* FIXME - why not send the phys page to begin with? */
410 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
411 unsigned long page);
412 int mc_idx;
413 int nr_csrows;
414 struct csrow_info *csrows;
415 /*
416 * FIXME - what about controllers on other busses? - IDs must be
417 * unique. dev pointer should be sufficiently unique, but
418 * BUS:SLOT.FUNC numbers may not be unique.
419 */
420 struct device *dev;
421 const char *mod_name;
422 const char *mod_ver;
423 const char *ctl_name;
424 const char *dev_name;
425 char proc_name[MC_PROC_NAME_MAX_LEN + 1];
426 void *pvt_info;
427 u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
428 u32 ce_noinfo_count; /* Correctable Errors w/o info */
429 u32 ue_count; /* Total Uncorrectable Errors for this MC */
430 u32 ce_count; /* Total Correctable Errors for this MC */
431 unsigned long start_time; /* mci load start time (in jiffies) */
432
433 struct completion complete;
434
435 /* edac sysfs device control */
436 struct kobject edac_mci_kobj;
437
438 /* list for all grp instances within a mc */
439 struct list_head grp_kobj_list;
440
441 /* Additional top controller level attributes, but specified
442 * by the low level driver.
443 *
444 * Set by the low level driver to provide attributes at the
445 * controller level, same level as 'ue_count' and 'ce_count' above.
446 * An array of structures, NULL terminated
447 *
448 * If attributes are desired, then set to array of attributes
449 * If no attributes are desired, leave NULL
450 */
451 const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
452
453 /* work struct for this MC */
454 struct delayed_work work;
455
456 /* the internal state of this controller instance */
457 int op_state;
458};
459
Dave Jiangc0d12172007-07-19 01:49:46 -0700460#endif