edac.h 16 KB

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