edac_core.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /*
  2. * Defines, structures, APIs for edac_core module
  3. *
  4. * (C) 2007 Linux Networx (http://lnxi.com)
  5. * This file may be distributed under the terms of the
  6. * GNU General Public License.
  7. *
  8. * Written by Thayne Harbaugh
  9. * Based on work by Dan Hollis <goemon at anime dot net> and others.
  10. * http://www.anime.net/~goemon/linux-ecc/
  11. *
  12. * NMI handling support added by
  13. * Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>
  14. *
  15. * Refactored for multi-source files:
  16. * Doug Thompson <norsk5@xmission.com>
  17. *
  18. */
  19. #ifndef _EDAC_CORE_H_
  20. #define _EDAC_CORE_H_
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/module.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/smp.h>
  26. #include <linux/pci.h>
  27. #include <linux/time.h>
  28. #include <linux/nmi.h>
  29. #include <linux/rcupdate.h>
  30. #include <linux/completion.h>
  31. #include <linux/kobject.h>
  32. #include <linux/platform_device.h>
  33. #define EDAC_MC_LABEL_LEN 31
  34. #define MC_PROC_NAME_MAX_LEN 7
  35. #if PAGE_SHIFT < 20
  36. #define PAGES_TO_MiB( pages ) ( ( pages ) >> ( 20 - PAGE_SHIFT ) )
  37. #else /* PAGE_SHIFT > 20 */
  38. #define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) )
  39. #endif
  40. #define edac_printk(level, prefix, fmt, arg...) \
  41. printk(level "EDAC " prefix ": " fmt, ##arg)
  42. #define edac_mc_printk(mci, level, fmt, arg...) \
  43. printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
  44. #define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
  45. printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
  46. /* prefixes for edac_printk() and edac_mc_printk() */
  47. #define EDAC_MC "MC"
  48. #define EDAC_PCI "PCI"
  49. #define EDAC_DEBUG "DEBUG"
  50. #ifdef CONFIG_EDAC_DEBUG
  51. extern int edac_debug_level;
  52. #define edac_debug_printk(level, fmt, arg...) \
  53. do { \
  54. if (level <= edac_debug_level) \
  55. edac_printk(KERN_DEBUG, EDAC_DEBUG, fmt, ##arg); \
  56. } while(0)
  57. #define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ )
  58. #define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ )
  59. #define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ )
  60. #define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ )
  61. #define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ )
  62. #else /* !CONFIG_EDAC_DEBUG */
  63. #define debugf0( ... )
  64. #define debugf1( ... )
  65. #define debugf2( ... )
  66. #define debugf3( ... )
  67. #define debugf4( ... )
  68. #endif /* !CONFIG_EDAC_DEBUG */
  69. #define BIT(x) (1 << (x))
  70. #define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
  71. PCI_DEVICE_ID_ ## vend ## _ ## dev
  72. #if defined(CONFIG_X86) && defined(CONFIG_PCI)
  73. #define dev_name(dev) pci_name(to_pci_dev(dev))
  74. #else
  75. #define dev_name(dev) to_platform_device(dev)->name
  76. #endif
  77. /* memory devices */
  78. enum dev_type {
  79. DEV_UNKNOWN = 0,
  80. DEV_X1,
  81. DEV_X2,
  82. DEV_X4,
  83. DEV_X8,
  84. DEV_X16,
  85. DEV_X32, /* Do these parts exist? */
  86. DEV_X64 /* Do these parts exist? */
  87. };
  88. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  89. #define DEV_FLAG_X1 BIT(DEV_X1)
  90. #define DEV_FLAG_X2 BIT(DEV_X2)
  91. #define DEV_FLAG_X4 BIT(DEV_X4)
  92. #define DEV_FLAG_X8 BIT(DEV_X8)
  93. #define DEV_FLAG_X16 BIT(DEV_X16)
  94. #define DEV_FLAG_X32 BIT(DEV_X32)
  95. #define DEV_FLAG_X64 BIT(DEV_X64)
  96. /* memory types */
  97. enum mem_type {
  98. MEM_EMPTY = 0, /* Empty csrow */
  99. MEM_RESERVED, /* Reserved csrow type */
  100. MEM_UNKNOWN, /* Unknown csrow type */
  101. MEM_FPM, /* Fast page mode */
  102. MEM_EDO, /* Extended data out */
  103. MEM_BEDO, /* Burst Extended data out */
  104. MEM_SDR, /* Single data rate SDRAM */
  105. MEM_RDR, /* Registered single data rate SDRAM */
  106. MEM_DDR, /* Double data rate SDRAM */
  107. MEM_RDDR, /* Registered Double data rate SDRAM */
  108. MEM_RMBS, /* Rambus DRAM */
  109. MEM_DDR2, /* DDR2 RAM */
  110. MEM_FB_DDR2, /* fully buffered DDR2 */
  111. MEM_RDDR2, /* Registered DDR2 RAM */
  112. };
  113. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  114. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  115. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  116. #define MEM_FLAG_FPM BIT(MEM_FPM)
  117. #define MEM_FLAG_EDO BIT(MEM_EDO)
  118. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  119. #define MEM_FLAG_SDR BIT(MEM_SDR)
  120. #define MEM_FLAG_RDR BIT(MEM_RDR)
  121. #define MEM_FLAG_DDR BIT(MEM_DDR)
  122. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  123. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  124. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  125. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  126. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  127. /* chipset Error Detection and Correction capabilities and mode */
  128. enum edac_type {
  129. EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
  130. EDAC_NONE, /* Doesnt support ECC */
  131. EDAC_RESERVED, /* Reserved ECC type */
  132. EDAC_PARITY, /* Detects parity errors */
  133. EDAC_EC, /* Error Checking - no correction */
  134. EDAC_SECDED, /* Single bit error correction, Double detection */
  135. EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
  136. EDAC_S4ECD4ED, /* Chipkill x4 devices */
  137. EDAC_S8ECD8ED, /* Chipkill x8 devices */
  138. EDAC_S16ECD16ED, /* Chipkill x16 devices */
  139. };
  140. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  141. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  142. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  143. #define EDAC_FLAG_EC BIT(EDAC_EC)
  144. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  145. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  146. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  147. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  148. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  149. /* scrubbing capabilities */
  150. enum scrub_type {
  151. SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
  152. SCRUB_NONE, /* No scrubber */
  153. SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
  154. SCRUB_SW_SRC, /* Software scrub only errors */
  155. SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
  156. SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
  157. SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
  158. SCRUB_HW_SRC, /* Hardware scrub only errors */
  159. SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
  160. SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
  161. };
  162. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  163. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC_CORR)
  164. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC_CORR)
  165. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  166. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  167. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC_CORR)
  168. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC_CORR)
  169. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  170. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  171. /*
  172. * There are several things to be aware of that aren't at all obvious:
  173. *
  174. *
  175. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  176. *
  177. * These are some of the many terms that are thrown about that don't always
  178. * mean what people think they mean (Inconceivable!). In the interest of
  179. * creating a common ground for discussion, terms and their definitions
  180. * will be established.
  181. *
  182. * Memory devices: The individual chip on a memory stick. These devices
  183. * commonly output 4 and 8 bits each. Grouping several
  184. * of these in parallel provides 64 bits which is common
  185. * for a memory stick.
  186. *
  187. * Memory Stick: A printed circuit board that agregates multiple
  188. * memory devices in parallel. This is the atomic
  189. * memory component that is purchaseable by Joe consumer
  190. * and loaded into a memory socket.
  191. *
  192. * Socket: A physical connector on the motherboard that accepts
  193. * a single memory stick.
  194. *
  195. * Channel: Set of memory devices on a memory stick that must be
  196. * grouped in parallel with one or more additional
  197. * channels from other memory sticks. This parallel
  198. * grouping of the output from multiple channels are
  199. * necessary for the smallest granularity of memory access.
  200. * Some memory controllers are capable of single channel -
  201. * which means that memory sticks can be loaded
  202. * individually. Other memory controllers are only
  203. * capable of dual channel - which means that memory
  204. * sticks must be loaded as pairs (see "socket set").
  205. *
  206. * Chip-select row: All of the memory devices that are selected together.
  207. * for a single, minimum grain of memory access.
  208. * This selects all of the parallel memory devices across
  209. * all of the parallel channels. Common chip-select rows
  210. * for single channel are 64 bits, for dual channel 128
  211. * bits.
  212. *
  213. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memmory.
  214. * Motherboards commonly drive two chip-select pins to
  215. * a memory stick. A single-ranked stick, will occupy
  216. * only one of those rows. The other will be unused.
  217. *
  218. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  219. * access different sets of memory devices. The two
  220. * rows cannot be accessed concurrently.
  221. *
  222. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  223. * A double-sided stick has two chip-select rows which
  224. * access different sets of memory devices. The two
  225. * rows cannot be accessed concurrently. "Double-sided"
  226. * is irrespective of the memory devices being mounted
  227. * on both sides of the memory stick.
  228. *
  229. * Socket set: All of the memory sticks that are required for for
  230. * a single memory access or all of the memory sticks
  231. * spanned by a chip-select row. A single socket set
  232. * has two chip-select rows and if double-sided sticks
  233. * are used these will occupy those chip-select rows.
  234. *
  235. * Bank: This term is avoided because it is unclear when
  236. * needing to distinguish between chip-select rows and
  237. * socket sets.
  238. *
  239. * Controller pages:
  240. *
  241. * Physical pages:
  242. *
  243. * Virtual pages:
  244. *
  245. *
  246. * STRUCTURE ORGANIZATION AND CHOICES
  247. *
  248. *
  249. *
  250. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  251. */
  252. struct channel_info {
  253. int chan_idx; /* channel index */
  254. u32 ce_count; /* Correctable Errors for this CHANNEL */
  255. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  256. struct csrow_info *csrow; /* the parent */
  257. };
  258. struct csrow_info {
  259. unsigned long first_page; /* first page number in dimm */
  260. unsigned long last_page; /* last page number in dimm */
  261. unsigned long page_mask; /* used for interleaving -
  262. * 0UL for non intlv
  263. */
  264. u32 nr_pages; /* number of pages in csrow */
  265. u32 grain; /* granularity of reported error in bytes */
  266. int csrow_idx; /* the chip-select row */
  267. enum dev_type dtype; /* memory device type */
  268. u32 ue_count; /* Uncorrectable Errors for this csrow */
  269. u32 ce_count; /* Correctable Errors for this csrow */
  270. enum mem_type mtype; /* memory csrow type */
  271. enum edac_type edac_mode; /* EDAC mode for this csrow */
  272. struct mem_ctl_info *mci; /* the parent */
  273. struct kobject kobj; /* sysfs kobject for this csrow */
  274. struct completion kobj_complete;
  275. /* FIXME the number of CHANNELs might need to become dynamic */
  276. u32 nr_channels;
  277. struct channel_info *channels;
  278. };
  279. struct mem_ctl_info {
  280. struct list_head link; /* for global list of mem_ctl_info structs */
  281. unsigned long mtype_cap; /* memory types supported by mc */
  282. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  283. unsigned long edac_cap; /* configuration capabilities - this is
  284. * closely related to edac_ctl_cap. The
  285. * difference is that the controller may be
  286. * capable of s4ecd4ed which would be listed
  287. * in edac_ctl_cap, but if channels aren't
  288. * capable of s4ecd4ed then the edac_cap would
  289. * not have that capability.
  290. */
  291. unsigned long scrub_cap; /* chipset scrub capabilities */
  292. enum scrub_type scrub_mode; /* current scrub mode */
  293. /* Translates sdram memory scrub rate given in bytes/sec to the
  294. internal representation and configures whatever else needs
  295. to be configured.
  296. */
  297. int (*set_sdram_scrub_rate) (struct mem_ctl_info *mci, u32 *bw);
  298. /* Get the current sdram memory scrub rate from the internal
  299. representation and converts it to the closest matching
  300. bandwith in bytes/sec.
  301. */
  302. int (*get_sdram_scrub_rate) (struct mem_ctl_info *mci, u32 *bw);
  303. /* pointer to edac checking routine */
  304. void (*edac_check) (struct mem_ctl_info * mci);
  305. /*
  306. * Remaps memory pages: controller pages to physical pages.
  307. * For most MC's, this will be NULL.
  308. */
  309. /* FIXME - why not send the phys page to begin with? */
  310. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  311. unsigned long page);
  312. int mc_idx;
  313. int nr_csrows;
  314. struct csrow_info *csrows;
  315. /*
  316. * FIXME - what about controllers on other busses? - IDs must be
  317. * unique. dev pointer should be sufficiently unique, but
  318. * BUS:SLOT.FUNC numbers may not be unique.
  319. */
  320. struct device *dev;
  321. const char *mod_name;
  322. const char *mod_ver;
  323. const char *ctl_name;
  324. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  325. void *pvt_info;
  326. u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
  327. u32 ce_noinfo_count; /* Correctable Errors w/o info */
  328. u32 ue_count; /* Total Uncorrectable Errors for this MC */
  329. u32 ce_count; /* Total Correctable Errors for this MC */
  330. unsigned long start_time; /* mci load start time (in jiffies) */
  331. /* this stuff is for safe removal of mc devices from global list while
  332. * NMI handlers may be traversing list
  333. */
  334. struct rcu_head rcu;
  335. struct completion complete;
  336. /* edac sysfs device control */
  337. struct kobject edac_mci_kobj;
  338. struct completion kobj_complete;
  339. };
  340. #ifdef CONFIG_PCI
  341. /* write all or some bits in a byte-register*/
  342. static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
  343. u8 mask)
  344. {
  345. if (mask != 0xff) {
  346. u8 buf;
  347. pci_read_config_byte(pdev, offset, &buf);
  348. value &= mask;
  349. buf &= ~mask;
  350. value |= buf;
  351. }
  352. pci_write_config_byte(pdev, offset, value);
  353. }
  354. /* write all or some bits in a word-register*/
  355. static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
  356. u16 value, u16 mask)
  357. {
  358. if (mask != 0xffff) {
  359. u16 buf;
  360. pci_read_config_word(pdev, offset, &buf);
  361. value &= mask;
  362. buf &= ~mask;
  363. value |= buf;
  364. }
  365. pci_write_config_word(pdev, offset, value);
  366. }
  367. /* write all or some bits in a dword-register*/
  368. static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
  369. u32 value, u32 mask)
  370. {
  371. if (mask != 0xffff) {
  372. u32 buf;
  373. pci_read_config_dword(pdev, offset, &buf);
  374. value &= mask;
  375. buf &= ~mask;
  376. value |= buf;
  377. }
  378. pci_write_config_dword(pdev, offset, value);
  379. }
  380. #endif /* CONFIG_PCI */
  381. extern struct mem_ctl_info * edac_mc_find(int idx);
  382. extern int edac_mc_add_mc(struct mem_ctl_info *mci,int mc_idx);
  383. extern struct mem_ctl_info * edac_mc_del_mc(struct device *dev);
  384. extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
  385. unsigned long page);
  386. /*
  387. * The no info errors are used when error overflows are reported.
  388. * There are a limited number of error logging registers that can
  389. * be exausted. When all registers are exhausted and an additional
  390. * error occurs then an error overflow register records that an
  391. * error occured and the type of error, but doesn't have any
  392. * further information. The ce/ue versions make for cleaner
  393. * reporting logic and function interface - reduces conditional
  394. * statement clutter and extra function arguments.
  395. */
  396. extern void edac_mc_handle_ce(struct mem_ctl_info *mci,
  397. unsigned long page_frame_number, unsigned long offset_in_page,
  398. unsigned long syndrome, int row, int channel,
  399. const char *msg);
  400. extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,
  401. const char *msg);
  402. extern void edac_mc_handle_ue(struct mem_ctl_info *mci,
  403. unsigned long page_frame_number, unsigned long offset_in_page,
  404. int row, const char *msg);
  405. extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
  406. const char *msg);
  407. extern void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
  408. unsigned int csrow,
  409. unsigned int channel0,
  410. unsigned int channel1,
  411. char *msg);
  412. extern void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
  413. unsigned int csrow,
  414. unsigned int channel,
  415. char *msg);
  416. /*
  417. * This kmalloc's and initializes all the structures.
  418. * Can't be used if all structures don't have the same lifetime.
  419. */
  420. extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
  421. unsigned nr_chans);
  422. /* Free an mc previously allocated by edac_mc_alloc() */
  423. extern void edac_mc_free(struct mem_ctl_info *mci);
  424. #endif /* _EDAC_CORE_H_ */