edac_mc.h 14 KB

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