edac.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. /* memory types */
  64. enum mem_type {
  65. MEM_EMPTY = 0, /* Empty csrow */
  66. MEM_RESERVED, /* Reserved csrow type */
  67. MEM_UNKNOWN, /* Unknown csrow type */
  68. MEM_FPM, /* Fast page mode */
  69. MEM_EDO, /* Extended data out */
  70. MEM_BEDO, /* Burst Extended data out */
  71. MEM_SDR, /* Single data rate SDRAM */
  72. MEM_RDR, /* Registered single data rate SDRAM */
  73. MEM_DDR, /* Double data rate SDRAM */
  74. MEM_RDDR, /* Registered Double data rate SDRAM */
  75. MEM_RMBS, /* Rambus DRAM */
  76. MEM_DDR2, /* DDR2 RAM */
  77. MEM_FB_DDR2, /* fully buffered DDR2 */
  78. MEM_RDDR2, /* Registered DDR2 RAM */
  79. MEM_XDR, /* Rambus XDR */
  80. MEM_DDR3, /* DDR3 RAM */
  81. MEM_RDDR3, /* Registered DDR3 RAM */
  82. };
  83. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  84. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  85. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  86. #define MEM_FLAG_FPM BIT(MEM_FPM)
  87. #define MEM_FLAG_EDO BIT(MEM_EDO)
  88. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  89. #define MEM_FLAG_SDR BIT(MEM_SDR)
  90. #define MEM_FLAG_RDR BIT(MEM_RDR)
  91. #define MEM_FLAG_DDR BIT(MEM_DDR)
  92. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  93. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  94. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  95. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  96. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  97. #define MEM_FLAG_XDR BIT(MEM_XDR)
  98. #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
  99. #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
  100. /* chipset Error Detection and Correction capabilities and mode */
  101. enum edac_type {
  102. EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
  103. EDAC_NONE, /* Doesn't support ECC */
  104. EDAC_RESERVED, /* Reserved ECC type */
  105. EDAC_PARITY, /* Detects parity errors */
  106. EDAC_EC, /* Error Checking - no correction */
  107. EDAC_SECDED, /* Single bit error correction, Double detection */
  108. EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
  109. EDAC_S4ECD4ED, /* Chipkill x4 devices */
  110. EDAC_S8ECD8ED, /* Chipkill x8 devices */
  111. EDAC_S16ECD16ED, /* Chipkill x16 devices */
  112. };
  113. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  114. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  115. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  116. #define EDAC_FLAG_EC BIT(EDAC_EC)
  117. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  118. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  119. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  120. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  121. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  122. /* scrubbing capabilities */
  123. enum scrub_type {
  124. SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
  125. SCRUB_NONE, /* No scrubber */
  126. SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
  127. SCRUB_SW_SRC, /* Software scrub only errors */
  128. SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
  129. SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
  130. SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
  131. SCRUB_HW_SRC, /* Hardware scrub only errors */
  132. SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
  133. SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
  134. };
  135. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  136. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  137. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  138. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  139. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  140. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  141. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  142. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  143. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  144. /* EDAC internal operation states */
  145. #define OP_ALLOC 0x100
  146. #define OP_RUNNING_POLL 0x201
  147. #define OP_RUNNING_INTERRUPT 0x202
  148. #define OP_RUNNING_POLL_INTR 0x203
  149. #define OP_OFFLINE 0x300
  150. /*
  151. * There are several things to be aware of that aren't at all obvious:
  152. *
  153. *
  154. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  155. *
  156. * These are some of the many terms that are thrown about that don't always
  157. * mean what people think they mean (Inconceivable!). In the interest of
  158. * creating a common ground for discussion, terms and their definitions
  159. * will be established.
  160. *
  161. * Memory devices: The individual chip on a memory stick. These devices
  162. * commonly output 4 and 8 bits each. Grouping several
  163. * of these in parallel provides 64 bits which is common
  164. * for a memory stick.
  165. *
  166. * Memory Stick: A printed circuit board that aggregates multiple
  167. * memory devices in parallel. This is the atomic
  168. * memory component that is purchaseable by Joe consumer
  169. * and loaded into a memory socket.
  170. *
  171. * Socket: A physical connector on the motherboard that accepts
  172. * a single memory stick.
  173. *
  174. * Channel: Set of memory devices on a memory stick that must be
  175. * grouped in parallel with one or more additional
  176. * channels from other memory sticks. This parallel
  177. * grouping of the output from multiple channels are
  178. * necessary for the smallest granularity of memory access.
  179. * Some memory controllers are capable of single channel -
  180. * which means that memory sticks can be loaded
  181. * individually. Other memory controllers are only
  182. * capable of dual channel - which means that memory
  183. * sticks must be loaded as pairs (see "socket set").
  184. *
  185. * Chip-select row: All of the memory devices that are selected together.
  186. * for a single, minimum grain of memory access.
  187. * This selects all of the parallel memory devices across
  188. * all of the parallel channels. Common chip-select rows
  189. * for single channel are 64 bits, for dual channel 128
  190. * bits.
  191. *
  192. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
  193. * Motherboards commonly drive two chip-select pins to
  194. * a memory stick. A single-ranked stick, will occupy
  195. * only one of those rows. The other will be unused.
  196. *
  197. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  198. * access different sets of memory devices. The two
  199. * rows cannot be accessed concurrently.
  200. *
  201. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  202. * A double-sided stick has two chip-select rows which
  203. * access different sets of memory devices. The two
  204. * rows cannot be accessed concurrently. "Double-sided"
  205. * is irrespective of the memory devices being mounted
  206. * on both sides of the memory stick.
  207. *
  208. * Socket set: All of the memory sticks that are required for
  209. * a single memory access or all of the memory sticks
  210. * spanned by a chip-select row. A single socket set
  211. * has two chip-select rows and if double-sided sticks
  212. * are used these will occupy those chip-select rows.
  213. *
  214. * Bank: This term is avoided because it is unclear when
  215. * needing to distinguish between chip-select rows and
  216. * socket sets.
  217. *
  218. * Controller pages:
  219. *
  220. * Physical pages:
  221. *
  222. * Virtual pages:
  223. *
  224. *
  225. * STRUCTURE ORGANIZATION AND CHOICES
  226. *
  227. *
  228. *
  229. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  230. */
  231. struct channel_info {
  232. int chan_idx; /* channel index */
  233. u32 ce_count; /* Correctable Errors for this CHANNEL */
  234. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  235. struct csrow_info *csrow; /* the parent */
  236. };
  237. struct csrow_info {
  238. unsigned long first_page; /* first page number in dimm */
  239. unsigned long last_page; /* last page number in dimm */
  240. unsigned long page_mask; /* used for interleaving -
  241. * 0UL for non intlv
  242. */
  243. u32 nr_pages; /* number of pages in csrow */
  244. u32 grain; /* granularity of reported error in bytes */
  245. int csrow_idx; /* the chip-select row */
  246. enum dev_type dtype; /* memory device type */
  247. u32 ue_count; /* Uncorrectable Errors for this csrow */
  248. u32 ce_count; /* Correctable Errors for this csrow */
  249. enum mem_type mtype; /* memory csrow type */
  250. enum edac_type edac_mode; /* EDAC mode for this csrow */
  251. struct mem_ctl_info *mci; /* the parent */
  252. struct kobject kobj; /* sysfs kobject for this csrow */
  253. /* channel information for this csrow */
  254. u32 nr_channels;
  255. struct channel_info *channels;
  256. };
  257. struct mcidev_sysfs_group {
  258. const char *name; /* group name */
  259. const struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */
  260. };
  261. struct mcidev_sysfs_group_kobj {
  262. struct list_head list; /* list for all instances within a mc */
  263. struct kobject kobj; /* kobj for the group */
  264. const struct mcidev_sysfs_group *grp; /* group description table */
  265. struct mem_ctl_info *mci; /* the parent */
  266. };
  267. /* mcidev_sysfs_attribute structure
  268. * used for driver sysfs attributes and in mem_ctl_info
  269. * sysfs top level entries
  270. */
  271. struct mcidev_sysfs_attribute {
  272. /* It should use either attr or grp */
  273. struct attribute attr;
  274. const struct mcidev_sysfs_group *grp; /* Points to a group of attributes */
  275. /* Ops for show/store values at the attribute - not used on group */
  276. ssize_t (*show)(struct mem_ctl_info *,char *);
  277. ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
  278. };
  279. /* MEMORY controller information structure
  280. */
  281. struct mem_ctl_info {
  282. struct list_head link; /* for global list of mem_ctl_info structs */
  283. struct module *owner; /* Module owner of this control struct */
  284. unsigned long mtype_cap; /* memory types supported by mc */
  285. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  286. unsigned long edac_cap; /* configuration capabilities - this is
  287. * closely related to edac_ctl_cap. The
  288. * difference is that the controller may be
  289. * capable of s4ecd4ed which would be listed
  290. * in edac_ctl_cap, but if channels aren't
  291. * capable of s4ecd4ed then the edac_cap would
  292. * not have that capability.
  293. */
  294. unsigned long scrub_cap; /* chipset scrub capabilities */
  295. enum scrub_type scrub_mode; /* current scrub mode */
  296. /* Translates sdram memory scrub rate given in bytes/sec to the
  297. internal representation and configures whatever else needs
  298. to be configured.
  299. */
  300. int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
  301. /* Get the current sdram memory scrub rate from the internal
  302. representation and converts it to the closest matching
  303. bandwidth in bytes/sec.
  304. */
  305. int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
  306. /* pointer to edac checking routine */
  307. void (*edac_check) (struct mem_ctl_info * mci);
  308. /*
  309. * Remaps memory pages: controller pages to physical pages.
  310. * For most MC's, this will be NULL.
  311. */
  312. /* FIXME - why not send the phys page to begin with? */
  313. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  314. unsigned long page);
  315. int mc_idx;
  316. int nr_csrows;
  317. struct csrow_info *csrows;
  318. /*
  319. * FIXME - what about controllers on other busses? - IDs must be
  320. * unique. dev pointer should be sufficiently unique, but
  321. * BUS:SLOT.FUNC numbers may not be unique.
  322. */
  323. struct device *dev;
  324. const char *mod_name;
  325. const char *mod_ver;
  326. const char *ctl_name;
  327. const char *dev_name;
  328. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  329. void *pvt_info;
  330. u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
  331. u32 ce_noinfo_count; /* Correctable Errors w/o info */
  332. u32 ue_count; /* Total Uncorrectable Errors for this MC */
  333. u32 ce_count; /* Total Correctable Errors for this MC */
  334. unsigned long start_time; /* mci load start time (in jiffies) */
  335. struct completion complete;
  336. /* edac sysfs device control */
  337. struct kobject edac_mci_kobj;
  338. /* list for all grp instances within a mc */
  339. struct list_head grp_kobj_list;
  340. /* Additional top controller level attributes, but specified
  341. * by the low level driver.
  342. *
  343. * Set by the low level driver to provide attributes at the
  344. * controller level, same level as 'ue_count' and 'ce_count' above.
  345. * An array of structures, NULL terminated
  346. *
  347. * If attributes are desired, then set to array of attributes
  348. * If no attributes are desired, leave NULL
  349. */
  350. const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
  351. /* work struct for this MC */
  352. struct delayed_work work;
  353. /* the internal state of this controller instance */
  354. int op_state;
  355. };
  356. #endif