edac_mc.h 15 KB

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