edac_mc.h 15 KB

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