edac_core.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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. #include <linux/sysdev.h>
  34. #include <linux/workqueue.h>
  35. #define EDAC_MC_LABEL_LEN 31
  36. #define EDAC_DEVICE_NAME_LEN 31
  37. #define EDAC_ATTRIB_VALUE_LEN 15
  38. #define MC_PROC_NAME_MAX_LEN 7
  39. #if PAGE_SHIFT < 20
  40. #define PAGES_TO_MiB( pages ) ( ( pages ) >> ( 20 - PAGE_SHIFT ) )
  41. #else /* PAGE_SHIFT > 20 */
  42. #define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) )
  43. #endif
  44. #define edac_printk(level, prefix, fmt, arg...) \
  45. printk(level "EDAC " prefix ": " fmt, ##arg)
  46. #define edac_printk_verbose(level, prefix, fmt, arg...) \
  47. printk(level "EDAC " prefix ": " "in %s, line at %d: " fmt, \
  48. __FILE__, __LINE__, ##arg)
  49. #define edac_mc_printk(mci, level, fmt, arg...) \
  50. printk(level "EDAC MC%d: " fmt, mci->mc_idx, ##arg)
  51. #define edac_mc_chipset_printk(mci, level, prefix, fmt, arg...) \
  52. printk(level "EDAC " prefix " MC%d: " fmt, mci->mc_idx, ##arg)
  53. /* edac_device printk */
  54. #define edac_device_printk(ctl, level, fmt, arg...) \
  55. printk(level "EDAC DEVICE%d: " fmt, ctl->dev_idx, ##arg)
  56. /* edac_pci printk */
  57. #define edac_pci_printk(ctl, level, fmt, arg...) \
  58. printk(level "EDAC PCI%d: " fmt, ctl->pci_idx, ##arg)
  59. /* prefixes for edac_printk() and edac_mc_printk() */
  60. #define EDAC_MC "MC"
  61. #define EDAC_PCI "PCI"
  62. #define EDAC_DEBUG "DEBUG"
  63. #ifdef CONFIG_EDAC_DEBUG
  64. extern int edac_debug_level;
  65. extern const char *edac_mem_types[];
  66. #ifndef CONFIG_EDAC_DEBUG_VERBOSE
  67. #define edac_debug_printk(level, fmt, arg...) \
  68. do { \
  69. if (level <= edac_debug_level) \
  70. edac_printk(KERN_DEBUG, EDAC_DEBUG, \
  71. "%s: " fmt, __func__, ##arg); \
  72. } while (0)
  73. #else /* CONFIG_EDAC_DEBUG_VERBOSE */
  74. #define edac_debug_printk(level, fmt, arg...) \
  75. do { \
  76. if (level <= edac_debug_level) \
  77. edac_printk_verbose(KERN_DEBUG, EDAC_DEBUG, fmt, \
  78. ##arg); \
  79. } while (0)
  80. #endif
  81. #define debugf0( ... ) edac_debug_printk(0, __VA_ARGS__ )
  82. #define debugf1( ... ) edac_debug_printk(1, __VA_ARGS__ )
  83. #define debugf2( ... ) edac_debug_printk(2, __VA_ARGS__ )
  84. #define debugf3( ... ) edac_debug_printk(3, __VA_ARGS__ )
  85. #define debugf4( ... ) edac_debug_printk(4, __VA_ARGS__ )
  86. #else /* !CONFIG_EDAC_DEBUG */
  87. #define debugf0( ... )
  88. #define debugf1( ... )
  89. #define debugf2( ... )
  90. #define debugf3( ... )
  91. #define debugf4( ... )
  92. #endif /* !CONFIG_EDAC_DEBUG */
  93. #define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
  94. PCI_DEVICE_ID_ ## vend ## _ ## dev
  95. #define edac_dev_name(dev) (dev)->dev_name
  96. /* memory devices */
  97. enum dev_type {
  98. DEV_UNKNOWN = 0,
  99. DEV_X1,
  100. DEV_X2,
  101. DEV_X4,
  102. DEV_X8,
  103. DEV_X16,
  104. DEV_X32, /* Do these parts exist? */
  105. DEV_X64 /* Do these parts exist? */
  106. };
  107. #define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
  108. #define DEV_FLAG_X1 BIT(DEV_X1)
  109. #define DEV_FLAG_X2 BIT(DEV_X2)
  110. #define DEV_FLAG_X4 BIT(DEV_X4)
  111. #define DEV_FLAG_X8 BIT(DEV_X8)
  112. #define DEV_FLAG_X16 BIT(DEV_X16)
  113. #define DEV_FLAG_X32 BIT(DEV_X32)
  114. #define DEV_FLAG_X64 BIT(DEV_X64)
  115. /* memory types */
  116. enum mem_type {
  117. MEM_EMPTY = 0, /* Empty csrow */
  118. MEM_RESERVED, /* Reserved csrow type */
  119. MEM_UNKNOWN, /* Unknown csrow type */
  120. MEM_FPM, /* Fast page mode */
  121. MEM_EDO, /* Extended data out */
  122. MEM_BEDO, /* Burst Extended data out */
  123. MEM_SDR, /* Single data rate SDRAM */
  124. MEM_RDR, /* Registered single data rate SDRAM */
  125. MEM_DDR, /* Double data rate SDRAM */
  126. MEM_RDDR, /* Registered Double data rate SDRAM */
  127. MEM_RMBS, /* Rambus DRAM */
  128. MEM_DDR2, /* DDR2 RAM */
  129. MEM_FB_DDR2, /* fully buffered DDR2 */
  130. MEM_RDDR2, /* Registered DDR2 RAM */
  131. MEM_XDR, /* Rambus XDR */
  132. MEM_DDR3, /* DDR3 RAM */
  133. MEM_RDDR3, /* Registered DDR3 RAM */
  134. };
  135. #define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
  136. #define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
  137. #define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
  138. #define MEM_FLAG_FPM BIT(MEM_FPM)
  139. #define MEM_FLAG_EDO BIT(MEM_EDO)
  140. #define MEM_FLAG_BEDO BIT(MEM_BEDO)
  141. #define MEM_FLAG_SDR BIT(MEM_SDR)
  142. #define MEM_FLAG_RDR BIT(MEM_RDR)
  143. #define MEM_FLAG_DDR BIT(MEM_DDR)
  144. #define MEM_FLAG_RDDR BIT(MEM_RDDR)
  145. #define MEM_FLAG_RMBS BIT(MEM_RMBS)
  146. #define MEM_FLAG_DDR2 BIT(MEM_DDR2)
  147. #define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
  148. #define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
  149. #define MEM_FLAG_XDR BIT(MEM_XDR)
  150. #define MEM_FLAG_DDR3 BIT(MEM_DDR3)
  151. #define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
  152. /* chipset Error Detection and Correction capabilities and mode */
  153. enum edac_type {
  154. EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
  155. EDAC_NONE, /* Doesnt support ECC */
  156. EDAC_RESERVED, /* Reserved ECC type */
  157. EDAC_PARITY, /* Detects parity errors */
  158. EDAC_EC, /* Error Checking - no correction */
  159. EDAC_SECDED, /* Single bit error correction, Double detection */
  160. EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
  161. EDAC_S4ECD4ED, /* Chipkill x4 devices */
  162. EDAC_S8ECD8ED, /* Chipkill x8 devices */
  163. EDAC_S16ECD16ED, /* Chipkill x16 devices */
  164. };
  165. #define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
  166. #define EDAC_FLAG_NONE BIT(EDAC_NONE)
  167. #define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
  168. #define EDAC_FLAG_EC BIT(EDAC_EC)
  169. #define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
  170. #define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
  171. #define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
  172. #define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
  173. #define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
  174. /* scrubbing capabilities */
  175. enum scrub_type {
  176. SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
  177. SCRUB_NONE, /* No scrubber */
  178. SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
  179. SCRUB_SW_SRC, /* Software scrub only errors */
  180. SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
  181. SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
  182. SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
  183. SCRUB_HW_SRC, /* Hardware scrub only errors */
  184. SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
  185. SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
  186. };
  187. #define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
  188. #define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
  189. #define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
  190. #define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
  191. #define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
  192. #define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
  193. #define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
  194. #define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
  195. /* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
  196. /* EDAC internal operation states */
  197. #define OP_ALLOC 0x100
  198. #define OP_RUNNING_POLL 0x201
  199. #define OP_RUNNING_INTERRUPT 0x202
  200. #define OP_RUNNING_POLL_INTR 0x203
  201. #define OP_OFFLINE 0x300
  202. /*
  203. * There are several things to be aware of that aren't at all obvious:
  204. *
  205. *
  206. * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
  207. *
  208. * These are some of the many terms that are thrown about that don't always
  209. * mean what people think they mean (Inconceivable!). In the interest of
  210. * creating a common ground for discussion, terms and their definitions
  211. * will be established.
  212. *
  213. * Memory devices: The individual chip on a memory stick. These devices
  214. * commonly output 4 and 8 bits each. Grouping several
  215. * of these in parallel provides 64 bits which is common
  216. * for a memory stick.
  217. *
  218. * Memory Stick: A printed circuit board that agregates multiple
  219. * memory devices in parallel. This is the atomic
  220. * memory component that is purchaseable by Joe consumer
  221. * and loaded into a memory socket.
  222. *
  223. * Socket: A physical connector on the motherboard that accepts
  224. * a single memory stick.
  225. *
  226. * Channel: Set of memory devices on a memory stick that must be
  227. * grouped in parallel with one or more additional
  228. * channels from other memory sticks. This parallel
  229. * grouping of the output from multiple channels are
  230. * necessary for the smallest granularity of memory access.
  231. * Some memory controllers are capable of single channel -
  232. * which means that memory sticks can be loaded
  233. * individually. Other memory controllers are only
  234. * capable of dual channel - which means that memory
  235. * sticks must be loaded as pairs (see "socket set").
  236. *
  237. * Chip-select row: All of the memory devices that are selected together.
  238. * for a single, minimum grain of memory access.
  239. * This selects all of the parallel memory devices across
  240. * all of the parallel channels. Common chip-select rows
  241. * for single channel are 64 bits, for dual channel 128
  242. * bits.
  243. *
  244. * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memmory.
  245. * Motherboards commonly drive two chip-select pins to
  246. * a memory stick. A single-ranked stick, will occupy
  247. * only one of those rows. The other will be unused.
  248. *
  249. * Double-Ranked stick: A double-ranked stick has two chip-select rows which
  250. * access different sets of memory devices. The two
  251. * rows cannot be accessed concurrently.
  252. *
  253. * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
  254. * A double-sided stick has two chip-select rows which
  255. * access different sets of memory devices. The two
  256. * rows cannot be accessed concurrently. "Double-sided"
  257. * is irrespective of the memory devices being mounted
  258. * on both sides of the memory stick.
  259. *
  260. * Socket set: All of the memory sticks that are required for
  261. * a single memory access or all of the memory sticks
  262. * spanned by a chip-select row. A single socket set
  263. * has two chip-select rows and if double-sided sticks
  264. * are used these will occupy those chip-select rows.
  265. *
  266. * Bank: This term is avoided because it is unclear when
  267. * needing to distinguish between chip-select rows and
  268. * socket sets.
  269. *
  270. * Controller pages:
  271. *
  272. * Physical pages:
  273. *
  274. * Virtual pages:
  275. *
  276. *
  277. * STRUCTURE ORGANIZATION AND CHOICES
  278. *
  279. *
  280. *
  281. * PS - I enjoyed writing all that about as much as you enjoyed reading it.
  282. */
  283. struct channel_info {
  284. int chan_idx; /* channel index */
  285. u32 ce_count; /* Correctable Errors for this CHANNEL */
  286. char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
  287. struct csrow_info *csrow; /* the parent */
  288. };
  289. struct csrow_info {
  290. unsigned long first_page; /* first page number in dimm */
  291. unsigned long last_page; /* last page number in dimm */
  292. unsigned long page_mask; /* used for interleaving -
  293. * 0UL for non intlv
  294. */
  295. u32 nr_pages; /* number of pages in csrow */
  296. u32 grain; /* granularity of reported error in bytes */
  297. int csrow_idx; /* the chip-select row */
  298. enum dev_type dtype; /* memory device type */
  299. u32 ue_count; /* Uncorrectable Errors for this csrow */
  300. u32 ce_count; /* Correctable Errors for this csrow */
  301. enum mem_type mtype; /* memory csrow type */
  302. enum edac_type edac_mode; /* EDAC mode for this csrow */
  303. struct mem_ctl_info *mci; /* the parent */
  304. struct kobject kobj; /* sysfs kobject for this csrow */
  305. /* channel information for this csrow */
  306. u32 nr_channels;
  307. struct channel_info *channels;
  308. };
  309. /* mcidev_sysfs_attribute structure
  310. * used for driver sysfs attributes and in mem_ctl_info
  311. * sysfs top level entries
  312. */
  313. struct mcidev_sysfs_attribute {
  314. struct attribute attr;
  315. ssize_t (*show)(struct mem_ctl_info *,char *);
  316. ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
  317. };
  318. /* MEMORY controller information structure
  319. */
  320. struct mem_ctl_info {
  321. struct list_head link; /* for global list of mem_ctl_info structs */
  322. struct module *owner; /* Module owner of this control struct */
  323. unsigned long mtype_cap; /* memory types supported by mc */
  324. unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
  325. unsigned long edac_cap; /* configuration capabilities - this is
  326. * closely related to edac_ctl_cap. The
  327. * difference is that the controller may be
  328. * capable of s4ecd4ed which would be listed
  329. * in edac_ctl_cap, but if channels aren't
  330. * capable of s4ecd4ed then the edac_cap would
  331. * not have that capability.
  332. */
  333. unsigned long scrub_cap; /* chipset scrub capabilities */
  334. enum scrub_type scrub_mode; /* current scrub mode */
  335. /* Translates sdram memory scrub rate given in bytes/sec to the
  336. internal representation and configures whatever else needs
  337. to be configured.
  338. */
  339. int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 * bw);
  340. /* Get the current sdram memory scrub rate from the internal
  341. representation and converts it to the closest matching
  342. bandwith in bytes/sec.
  343. */
  344. int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 * bw);
  345. /* pointer to edac checking routine */
  346. void (*edac_check) (struct mem_ctl_info * mci);
  347. /*
  348. * Remaps memory pages: controller pages to physical pages.
  349. * For most MC's, this will be NULL.
  350. */
  351. /* FIXME - why not send the phys page to begin with? */
  352. unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
  353. unsigned long page);
  354. int mc_idx;
  355. int nr_csrows;
  356. struct csrow_info *csrows;
  357. /*
  358. * FIXME - what about controllers on other busses? - IDs must be
  359. * unique. dev pointer should be sufficiently unique, but
  360. * BUS:SLOT.FUNC numbers may not be unique.
  361. */
  362. struct device *dev;
  363. const char *mod_name;
  364. const char *mod_ver;
  365. const char *ctl_name;
  366. const char *dev_name;
  367. char proc_name[MC_PROC_NAME_MAX_LEN + 1];
  368. void *pvt_info;
  369. u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
  370. u32 ce_noinfo_count; /* Correctable Errors w/o info */
  371. u32 ue_count; /* Total Uncorrectable Errors for this MC */
  372. u32 ce_count; /* Total Correctable Errors for this MC */
  373. unsigned long start_time; /* mci load start time (in jiffies) */
  374. /* this stuff is for safe removal of mc devices from global list while
  375. * NMI handlers may be traversing list
  376. */
  377. struct rcu_head rcu;
  378. struct completion complete;
  379. /* edac sysfs device control */
  380. struct kobject edac_mci_kobj;
  381. /* Additional top controller level attributes, but specified
  382. * by the low level driver.
  383. *
  384. * Set by the low level driver to provide attributes at the
  385. * controller level, same level as 'ue_count' and 'ce_count' above.
  386. * An array of structures, NULL terminated
  387. *
  388. * If attributes are desired, then set to array of attributes
  389. * If no attributes are desired, leave NULL
  390. */
  391. struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
  392. /* work struct for this MC */
  393. struct delayed_work work;
  394. /* the internal state of this controller instance */
  395. int op_state;
  396. };
  397. /*
  398. * The following are the structures to provide for a generic
  399. * or abstract 'edac_device'. This set of structures and the
  400. * code that implements the APIs for the same, provide for
  401. * registering EDAC type devices which are NOT standard memory.
  402. *
  403. * CPU caches (L1 and L2)
  404. * DMA engines
  405. * Core CPU swithces
  406. * Fabric switch units
  407. * PCIe interface controllers
  408. * other EDAC/ECC type devices that can be monitored for
  409. * errors, etc.
  410. *
  411. * It allows for a 2 level set of hiearchry. For example:
  412. *
  413. * cache could be composed of L1, L2 and L3 levels of cache.
  414. * Each CPU core would have its own L1 cache, while sharing
  415. * L2 and maybe L3 caches.
  416. *
  417. * View them arranged, via the sysfs presentation:
  418. * /sys/devices/system/edac/..
  419. *
  420. * mc/ <existing memory device directory>
  421. * cpu/cpu0/.. <L1 and L2 block directory>
  422. * /L1-cache/ce_count
  423. * /ue_count
  424. * /L2-cache/ce_count
  425. * /ue_count
  426. * cpu/cpu1/.. <L1 and L2 block directory>
  427. * /L1-cache/ce_count
  428. * /ue_count
  429. * /L2-cache/ce_count
  430. * /ue_count
  431. * ...
  432. *
  433. * the L1 and L2 directories would be "edac_device_block's"
  434. */
  435. struct edac_device_counter {
  436. u32 ue_count;
  437. u32 ce_count;
  438. };
  439. /* forward reference */
  440. struct edac_device_ctl_info;
  441. struct edac_device_block;
  442. /* edac_dev_sysfs_attribute structure
  443. * used for driver sysfs attributes in mem_ctl_info
  444. * for extra controls and attributes:
  445. * like high level error Injection controls
  446. */
  447. struct edac_dev_sysfs_attribute {
  448. struct attribute attr;
  449. ssize_t (*show)(struct edac_device_ctl_info *, char *);
  450. ssize_t (*store)(struct edac_device_ctl_info *, const char *, size_t);
  451. };
  452. /* edac_dev_sysfs_block_attribute structure
  453. *
  454. * used in leaf 'block' nodes for adding controls/attributes
  455. *
  456. * each block in each instance of the containing control structure
  457. * can have an array of the following. The show and store functions
  458. * will be filled in with the show/store function in the
  459. * low level driver.
  460. *
  461. * The 'value' field will be the actual value field used for
  462. * counting
  463. */
  464. struct edac_dev_sysfs_block_attribute {
  465. struct attribute attr;
  466. ssize_t (*show)(struct kobject *, struct attribute *, char *);
  467. ssize_t (*store)(struct kobject *, struct attribute *,
  468. const char *, size_t);
  469. struct edac_device_block *block;
  470. unsigned int value;
  471. };
  472. /* device block control structure */
  473. struct edac_device_block {
  474. struct edac_device_instance *instance; /* Up Pointer */
  475. char name[EDAC_DEVICE_NAME_LEN + 1];
  476. struct edac_device_counter counters; /* basic UE and CE counters */
  477. int nr_attribs; /* how many attributes */
  478. /* this block's attributes, could be NULL */
  479. struct edac_dev_sysfs_block_attribute *block_attributes;
  480. /* edac sysfs device control */
  481. struct kobject kobj;
  482. };
  483. /* device instance control structure */
  484. struct edac_device_instance {
  485. struct edac_device_ctl_info *ctl; /* Up pointer */
  486. char name[EDAC_DEVICE_NAME_LEN + 4];
  487. struct edac_device_counter counters; /* instance counters */
  488. u32 nr_blocks; /* how many blocks */
  489. struct edac_device_block *blocks; /* block array */
  490. /* edac sysfs device control */
  491. struct kobject kobj;
  492. };
  493. /*
  494. * Abstract edac_device control info structure
  495. *
  496. */
  497. struct edac_device_ctl_info {
  498. /* for global list of edac_device_ctl_info structs */
  499. struct list_head link;
  500. struct module *owner; /* Module owner of this control struct */
  501. int dev_idx;
  502. /* Per instance controls for this edac_device */
  503. int log_ue; /* boolean for logging UEs */
  504. int log_ce; /* boolean for logging CEs */
  505. int panic_on_ue; /* boolean for panic'ing on an UE */
  506. unsigned poll_msec; /* number of milliseconds to poll interval */
  507. unsigned long delay; /* number of jiffies for poll_msec */
  508. /* Additional top controller level attributes, but specified
  509. * by the low level driver.
  510. *
  511. * Set by the low level driver to provide attributes at the
  512. * controller level, same level as 'ue_count' and 'ce_count' above.
  513. * An array of structures, NULL terminated
  514. *
  515. * If attributes are desired, then set to array of attributes
  516. * If no attributes are desired, leave NULL
  517. */
  518. struct edac_dev_sysfs_attribute *sysfs_attributes;
  519. /* pointer to main 'edac' class in sysfs */
  520. struct sysdev_class *edac_class;
  521. /* the internal state of this controller instance */
  522. int op_state;
  523. /* work struct for this instance */
  524. struct delayed_work work;
  525. /* pointer to edac polling checking routine:
  526. * If NOT NULL: points to polling check routine
  527. * If NULL: Then assumes INTERRUPT operation, where
  528. * MC driver will receive events
  529. */
  530. void (*edac_check) (struct edac_device_ctl_info * edac_dev);
  531. struct device *dev; /* pointer to device structure */
  532. const char *mod_name; /* module name */
  533. const char *ctl_name; /* edac controller name */
  534. const char *dev_name; /* pci/platform/etc... name */
  535. void *pvt_info; /* pointer to 'private driver' info */
  536. unsigned long start_time; /* edac_device load start time (jiffies) */
  537. /* these are for safe removal of mc devices from global list while
  538. * NMI handlers may be traversing list
  539. */
  540. struct rcu_head rcu;
  541. struct completion removal_complete;
  542. /* sysfs top name under 'edac' directory
  543. * and instance name:
  544. * cpu/cpu0/...
  545. * cpu/cpu1/...
  546. * cpu/cpu2/...
  547. * ...
  548. */
  549. char name[EDAC_DEVICE_NAME_LEN + 1];
  550. /* Number of instances supported on this control structure
  551. * and the array of those instances
  552. */
  553. u32 nr_instances;
  554. struct edac_device_instance *instances;
  555. /* Event counters for the this whole EDAC Device */
  556. struct edac_device_counter counters;
  557. /* edac sysfs device control for the 'name'
  558. * device this structure controls
  559. */
  560. struct kobject kobj;
  561. };
  562. /* To get from the instance's wq to the beginning of the ctl structure */
  563. #define to_edac_mem_ctl_work(w) \
  564. container_of(w, struct mem_ctl_info, work)
  565. #define to_edac_device_ctl_work(w) \
  566. container_of(w,struct edac_device_ctl_info,work)
  567. /*
  568. * The alloc() and free() functions for the 'edac_device' control info
  569. * structure. A MC driver will allocate one of these for each edac_device
  570. * it is going to control/register with the EDAC CORE.
  571. */
  572. extern struct edac_device_ctl_info *edac_device_alloc_ctl_info(
  573. unsigned sizeof_private,
  574. char *edac_device_name, unsigned nr_instances,
  575. char *edac_block_name, unsigned nr_blocks,
  576. unsigned offset_value,
  577. struct edac_dev_sysfs_block_attribute *block_attributes,
  578. unsigned nr_attribs,
  579. int device_index);
  580. /* The offset value can be:
  581. * -1 indicating no offset value
  582. * 0 for zero-based block numbers
  583. * 1 for 1-based block number
  584. * other for other-based block number
  585. */
  586. #define BLOCK_OFFSET_VALUE_OFF ((unsigned) -1)
  587. extern void edac_device_free_ctl_info(struct edac_device_ctl_info *ctl_info);
  588. #ifdef CONFIG_PCI
  589. struct edac_pci_counter {
  590. atomic_t pe_count;
  591. atomic_t npe_count;
  592. };
  593. /*
  594. * Abstract edac_pci control info structure
  595. *
  596. */
  597. struct edac_pci_ctl_info {
  598. /* for global list of edac_pci_ctl_info structs */
  599. struct list_head link;
  600. int pci_idx;
  601. struct sysdev_class *edac_class; /* pointer to class */
  602. /* the internal state of this controller instance */
  603. int op_state;
  604. /* work struct for this instance */
  605. struct delayed_work work;
  606. /* pointer to edac polling checking routine:
  607. * If NOT NULL: points to polling check routine
  608. * If NULL: Then assumes INTERRUPT operation, where
  609. * MC driver will receive events
  610. */
  611. void (*edac_check) (struct edac_pci_ctl_info * edac_dev);
  612. struct device *dev; /* pointer to device structure */
  613. const char *mod_name; /* module name */
  614. const char *ctl_name; /* edac controller name */
  615. const char *dev_name; /* pci/platform/etc... name */
  616. void *pvt_info; /* pointer to 'private driver' info */
  617. unsigned long start_time; /* edac_pci load start time (jiffies) */
  618. /* these are for safe removal of devices from global list while
  619. * NMI handlers may be traversing list
  620. */
  621. struct rcu_head rcu;
  622. struct completion complete;
  623. /* sysfs top name under 'edac' directory
  624. * and instance name:
  625. * cpu/cpu0/...
  626. * cpu/cpu1/...
  627. * cpu/cpu2/...
  628. * ...
  629. */
  630. char name[EDAC_DEVICE_NAME_LEN + 1];
  631. /* Event counters for the this whole EDAC Device */
  632. struct edac_pci_counter counters;
  633. /* edac sysfs device control for the 'name'
  634. * device this structure controls
  635. */
  636. struct kobject kobj;
  637. struct completion kobj_complete;
  638. };
  639. #define to_edac_pci_ctl_work(w) \
  640. container_of(w, struct edac_pci_ctl_info,work)
  641. /* write all or some bits in a byte-register*/
  642. static inline void pci_write_bits8(struct pci_dev *pdev, int offset, u8 value,
  643. u8 mask)
  644. {
  645. if (mask != 0xff) {
  646. u8 buf;
  647. pci_read_config_byte(pdev, offset, &buf);
  648. value &= mask;
  649. buf &= ~mask;
  650. value |= buf;
  651. }
  652. pci_write_config_byte(pdev, offset, value);
  653. }
  654. /* write all or some bits in a word-register*/
  655. static inline void pci_write_bits16(struct pci_dev *pdev, int offset,
  656. u16 value, u16 mask)
  657. {
  658. if (mask != 0xffff) {
  659. u16 buf;
  660. pci_read_config_word(pdev, offset, &buf);
  661. value &= mask;
  662. buf &= ~mask;
  663. value |= buf;
  664. }
  665. pci_write_config_word(pdev, offset, value);
  666. }
  667. /*
  668. * pci_write_bits32
  669. *
  670. * edac local routine to do pci_write_config_dword, but adds
  671. * a mask parameter. If mask is all ones, ignore the mask.
  672. * Otherwise utilize the mask to isolate specified bits
  673. *
  674. * write all or some bits in a dword-register
  675. */
  676. static inline void pci_write_bits32(struct pci_dev *pdev, int offset,
  677. u32 value, u32 mask)
  678. {
  679. if (mask != 0xffffffff) {
  680. u32 buf;
  681. pci_read_config_dword(pdev, offset, &buf);
  682. value &= mask;
  683. buf &= ~mask;
  684. value |= buf;
  685. }
  686. pci_write_config_dword(pdev, offset, value);
  687. }
  688. #endif /* CONFIG_PCI */
  689. extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
  690. unsigned nr_chans, int edac_index);
  691. extern int edac_mc_add_mc(struct mem_ctl_info *mci);
  692. extern void edac_mc_free(struct mem_ctl_info *mci);
  693. extern struct mem_ctl_info *edac_mc_find(int idx);
  694. extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);
  695. extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
  696. unsigned long page);
  697. /*
  698. * The no info errors are used when error overflows are reported.
  699. * There are a limited number of error logging registers that can
  700. * be exausted. When all registers are exhausted and an additional
  701. * error occurs then an error overflow register records that an
  702. * error occured and the type of error, but doesn't have any
  703. * further information. The ce/ue versions make for cleaner
  704. * reporting logic and function interface - reduces conditional
  705. * statement clutter and extra function arguments.
  706. */
  707. extern void edac_mc_handle_ce(struct mem_ctl_info *mci,
  708. unsigned long page_frame_number,
  709. unsigned long offset_in_page,
  710. unsigned long syndrome, int row, int channel,
  711. const char *msg);
  712. extern void edac_mc_handle_ce_no_info(struct mem_ctl_info *mci,
  713. const char *msg);
  714. extern void edac_mc_handle_ue(struct mem_ctl_info *mci,
  715. unsigned long page_frame_number,
  716. unsigned long offset_in_page, int row,
  717. const char *msg);
  718. extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
  719. const char *msg);
  720. extern void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci, unsigned int csrow,
  721. unsigned int channel0, unsigned int channel1,
  722. char *msg);
  723. extern void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci, unsigned int csrow,
  724. unsigned int channel, char *msg);
  725. /*
  726. * edac_device APIs
  727. */
  728. extern int edac_device_add_device(struct edac_device_ctl_info *edac_dev);
  729. extern struct edac_device_ctl_info *edac_device_del_device(struct device *dev);
  730. extern void edac_device_handle_ue(struct edac_device_ctl_info *edac_dev,
  731. int inst_nr, int block_nr, const char *msg);
  732. extern void edac_device_handle_ce(struct edac_device_ctl_info *edac_dev,
  733. int inst_nr, int block_nr, const char *msg);
  734. extern int edac_device_alloc_index(void);
  735. /*
  736. * edac_pci APIs
  737. */
  738. extern struct edac_pci_ctl_info *edac_pci_alloc_ctl_info(unsigned int sz_pvt,
  739. const char *edac_pci_name);
  740. extern void edac_pci_free_ctl_info(struct edac_pci_ctl_info *pci);
  741. extern void edac_pci_reset_delay_period(struct edac_pci_ctl_info *pci,
  742. unsigned long value);
  743. extern int edac_pci_alloc_index(void);
  744. extern int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx);
  745. extern struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev);
  746. extern struct edac_pci_ctl_info *edac_pci_create_generic_ctl(
  747. struct device *dev,
  748. const char *mod_name);
  749. extern void edac_pci_release_generic_ctl(struct edac_pci_ctl_info *pci);
  750. extern int edac_pci_create_sysfs(struct edac_pci_ctl_info *pci);
  751. extern void edac_pci_remove_sysfs(struct edac_pci_ctl_info *pci);
  752. /*
  753. * edac misc APIs
  754. */
  755. extern char *edac_op_state_to_string(int op_state);
  756. #endif /* _EDAC_CORE_H_ */