edac_core.h 27 KB

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