edac_core.h 27 KB

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